結果
問題 | No.1120 Strange Teacher |
ユーザー |
![]() |
提出日時 | 2020-07-22 21:48:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,044 bytes |
コンパイル時間 | 2,265 ms |
コンパイル使用メモリ | 160,564 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 15:30:44 |
合計ジャッジ時間 | 2,879 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 WA * 2 RE * 3 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long longconst 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) {assert(false);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 % 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;}}}