Little Elephant and Bamboo
All submissions for this problem are available.
Read problems statements in Mandarin Chinese here
Little Elephant from Zoo of Lviv likes bamboo very much. He currently has n stems of bamboo, Hi - height of i-th stem of bamboo (0-based numeration).
Today inspector Andrii from World Bamboo Association is visiting the plantation. He doesn't like current situation. He wants the height of i-th stem to be Di, for each i from 0 to n-1, inclusive.
Little Elephant is going to buy some special substance. One bottle of such substance he can use to single stem of bamboo. After using substance for stem i, the height of i-th stem is decrased by 1 and the height of j-th stem is increased by 1 for each j not equal to i. Note that it is possible for some of the stems to have negative height, but after all transformations all stems should have positive height.
Substance is very expensive. Help Little Elephant and find the minimal number of bottles of substance required for changing current plantation to one that inspector wants. If it's impossible, print -1.
First line contain single integer T - the number of test cases. T test cases follow. First line of each test case contains single integer n - the number of stems in the plantation. Second line contains n integers separated by single space - starting plantation. Next line of each test case contains n integers - plantation that inspector Andrii requires.
In T lines print T integers - the answers for the corresponding test cases.
1 <= T <= 50
1 <= n <= 50
1 <= Hi, Di <= 50
Input: 3 1 1 2 2 1 2 2 1 3 3 2 2 4 5 3 Output: -1 1 5
|Tags||ad-hoc, oct13, simple-easy, witua|
|Time Limit:||1.88586 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.