結果
問題 |
No.1120 Strange Teacher
|
ユーザー |
![]() |
提出日時 | 2020-07-22 21:44:07 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,099 bytes |
コンパイル時間 | 2,434 ms |
コンパイル使用メモリ | 77,688 KB |
実行使用メモリ | 66,860 KB |
最終ジャッジ日時 | 2024-06-22 15:03:42 |
合計ジャッジ時間 | 8,287 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 14 WA * 13 |
ソースコード
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; } long cnt = sum / (n - 2); long sum2 = 0; for (int i = 0; i < n; i++) { long val = (cnt - d[i]) / 2; if (val < 0) { System.out.println(-1); return; } sum2 += val; } System.out.println(-1); } }