eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Chemists

Chemists

The chemists had gathered to carry out an important experiment. That experiment required some tubes filled with liquid (each tube had to contain a certain amount of liquid). The experiment was set on \textbf{8} AM on the next day. They had worked hard, and there was the right amount of liquid in tubes by the end of the day. The chemists had decided to celebrate the occasion and, when morning came, they found out that someone had been pouring the liquid from and into the random tubes during the night. It is possible that this person had spilled the liquid or poured in an extra amount of it. Help the chemists to find out the minimum number of pourings to get the required amount of liquid in all tubes. There are \textbf{N} tubes with \textbf{S_i} liters of liquid in \textbf{i}^\{-th\} tube. It is allowed to pour any amount of liquid from any one tube to another. You have to get the right amount of liquid in each tube (\textbf{D_i} for \textbf{i}^\{-th\} tube) after the minimum number of pourings. \InputFile The first line of input contains an integer number \textbf{N}. The second line consists of \textbf{N} integer numbers \textbf{S_i} separated by space. The third line consists of \textbf{N} integer numbers \textbf{D_i} separated by space. \textbf{1} ≤ \textbf{N} ≤ \textbf{21}, \textbf{1} ≤ \textbf{S_i}, \textbf{D_i} ≤ \textbf{1000}. \OutputFile Output one number --- the minimum number of pourings, or \textbf{-1} if the pouring is impossible.
Лимит времени 0.75 секунд
Лимит использования памяти 256 MiB
Входные данные #1
7
1 2 3 4 5 6 7
7 4 5 1 2 6 3
Выходные данные #1
4
Источник Izhevsk STU Contest, Petrozavodsk training camp, February 6, 2009