問題一覧 > 通常問題

No.1120 Strange Teacher

レベル : / AI推定難易度 : 1100 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 226
作問者 : e869120 / テスター : maspy
お気に入りにしたユーザー ProblemId : 4630 / 自分の提出
問題文最終更新日: 2020-07-17 23:24:34
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 258 (順位表) の他の問題:

Problem Statement

$N$ students are taking Professor yuki's computer science class.
Yesterday, the final exam was held, and the student numbered $i$ scored $A_i$ points.

However, the professor was not satisfied with the exam results. Therefore, the professor wants to make the student numbered $i$ have $B_i$ points by performing the following operation some number of times.

  • Choose $1$ student, add $1$ point to that student, and subtract $1$ point from every other student. (Some students' scores may become negative as a result of this operation.)
Determine whether the professor's goal can be achieved. If it can, find the minimum number of operations.

Input

$N$
$A_1$ $A_2$ $\cdots$ $A_N$
$B_1$ $B_2$ $\cdots$ $B_N$

The $1$st line contains an integer $N$.
The $2$nd line contains integers $A_1, A_2, ..., A_N$ separated by spaces.
The $3$rd line contains integers $B_1, B_2, ..., B_N$ separated by spaces.

Output

If the professor's goal cannot be achieved, output -1.
If the professor's goal can be achieved, output the minimum number of operations as an integer.

Constraints

  • $2 \leq N \leq 100 \ 000$
  • $1 \leq A_i \leq 1 \ 000 \ 000$
  • $1 \leq B_i \leq 1 \ 000 \ 000$
  • All inputs are integers.

Sample

Sample 1
Input
4
100 100 99 100
99 99 100 99
Output
1

If the professor adds $1$ point to the $3$rd student and subtracts $1$ point from everyone else, the scores become $99, 99, 100, 99$ points in order starting from student $1$, as the professor wishes.

Sample 2
Input
4
90 90 90 90
80 60 100 60
Output
30

For example, performing the operations in the following order gives the result the professor wishes.

  • Perform the following operation $10$ times.
    • Add $1$ point to the $1$st student and subtract $1$ point from everyone else.
  • Perform the following operation $20$ times.
    • Add $1$ point to the $3$rd student and subtract $1$ point from everyone else.

Sample 3
Input
3
20 80 90
82 56 47
Output
-1

There is no way to perform the operations that gives the result the professor wishes.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。