結果
| 問題 |
No.1120 Strange Teacher
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2020-07-22 21:37:44 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,169 bytes |
| コンパイル時間 | 2,205 ms |
| コンパイル使用メモリ | 78,044 KB |
| 実行使用メモリ | 66,736 KB |
| 最終ジャッジ日時 | 2024-06-22 14:30:56 |
| 合計ジャッジ時間 | 8,515 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 WA * 1 |
ソースコード
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String[] sa = br.readLine().split(" ");
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(sa[i]);
}
sa = br.readLine().split(" ");
int[] b = new int[n];
for (int i = 0; i < n; i++) {
b[i] = Integer.parseInt(sa[i]);
}
br.close();
long sum = 0;
int[] d = new int[n];
for (int i = 0; i < n; i++) {
d[i] = a[i] - b[i];
sum += d[i];
}
if (n == 2) {
if (sum == 0) {
System.out.println(Math.abs(d[0]));
} else {
System.out.println(-1);
}
return;
}
if (sum < 0 || sum % (n - 2) != 0) {
System.out.println(-1);
return;
}
int cnt = (int) (sum / (n - 2));
int sum2 = 0;
for (int i = 0; i < n; i++) {
int val = (cnt - d[i]) / 2;
if (val < 0) {
System.out.println(-1);
return;
}
sum2 += val;
}
if (sum2 == cnt) {
System.out.println(cnt);
} else {
System.out.println(-1);
}
}
}
ks2m