結果
問題 | No.1120 Strange Teacher |
ユーザー |
![]() |
提出日時 | 2020-07-22 22:23:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 20 ms / 1,000 ms |
コード長 | 1,036 bytes |
コンパイル時間 | 1,448 ms |
コンパイル使用メモリ | 160,760 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 18:59:00 |
合計ジャッジ時間 | 2,861 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); vector<int> B(N); int sumA = 0; int sumB = 0; for (int i = 0; i < N; i++) { cin >> A[i]; sumA += A[i]; } for (int i = 0; i < N; i++) { cin >> B[i]; sumB += B[i]; } if (N == 2) { if (sumA != sumB) { cout << -1 << endl; } else { cout << abs(A[0] - B[0]) << endl; } } else { bool ok = true; if (sumA < sumB) { ok = false; } else { int k = sumA - sumB; if (k % (N - 2) != 0) { ok = false; } else { int tot = k / (N - 2); int c = 0; for (int i = 0; i < N; i++) { int t = (B[i] - A[i] + tot); if (t < 0 || t % 2 != 0) { ok = false; } int x = t / 2; A[i] += x - (tot - x); c += x; } if (c != tot) { ok = false; } if (ok) { cout << tot << endl; return 0; } } } if (!ok) { cout << -1 << endl; } } }