結果
| 問題 |
No.1120 Strange Teacher
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-19 14:04:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,068 bytes |
| コンパイル時間 | 2,032 ms |
| コンパイル使用メモリ | 198,676 KB |
| 最終ジャッジ日時 | 2025-01-17 03:50:14 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N; { cin >> N; }
vector<int> A(N); { for (int i = 0; i < N; ++i) cin >> A[i]; }
vector<int> B(N); { for (int i = 0; i < N; ++i) cin >> B[i]; }
if (N == 2) {
if (A[0] - B[0] == B[1] - A[0]) {
cout << abs(A[0] - B[0]) << endl;
} else {
cout << -1 << endl;
}
return 0;
}
int dSum = 0; {
for (int i = 0; i < N; ++i) dSum += A[i] - B[i];
}
if (dSum < 0 || dSum % (N - 2)) {
cout << -1 << endl;
return 0;
}
vector<int> dord(N); {
iota(dord.begin(), dord.end(), 0);
sort(dord.begin(), dord.end(), [&](int i, int j) { return B[i] - A[i] > B[j] - A[j]; });
}
int dGlobal = 0;
int opCnt = dSum / (N - 2);
for (int i : dord) {
int d = B[i] - (A[i] - dGlobal);
int q = (opCnt + d) / 2;
if (opCnt + d % 2 == 1 || q < 0 || opCnt < q) {
cout << -1 << endl;
return 0;
}
opCnt -= q;
dGlobal += q;
}
assert(opCnt == 0);
cout << (dSum / (N - 2)) << endl;
}