eolymp
bolt
Try our new interface for solving problems

Chemists

Zaman məhdudiyyəti 0.75 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB

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 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 N tubes with S_i liters of liquid in 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 (D_i for i^{-th} tube) after the minimum number of pourings.

Giriş verilənləri

The first line of input contains an integer number N. The second line consists of N integer numbers S_i separated by space. The third line consists of N integer numbers D_i separated by space. 1N21, 1S_i, D_i1000.

Çıxış verilənləri

Output one number — the minimum number of pourings, or -1 if the pouring is impossible.

Nümunə

Giriş verilənləri #1
7
1 2 3 4 5 6 7
7 4 5 1 2 6 3
Çıxış verilənləri #1
4
Mənbə Izhevsk STU Contest, Petrozavodsk training camp, February 6, 2009