結果

問題 No.1120 Strange Teacher
ユーザー ats5515
提出日時 2020-07-22 21:28:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 981 bytes
コンパイル時間 1,423 ms
コンパイル使用メモリ 160,964 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 13:37:07
合計ジャッジ時間 3,019 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 res = 0;
	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 % 2 != 0) {
						ok = false;
					}
					c += t / 2;
				}
				if (c != tot) {
					ok = false;
				}

				if (ok) {
					cout << tot << endl;
				}
			}
			if (!ok) {
				cout << -1 << endl;
			}
		}
	}
}
0