結果
| 問題 |
No.1120 Strange Teacher
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-02 14:20:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 1,000 ms |
| コード長 | 1,012 bytes |
| コンパイル時間 | 715 ms |
| コンパイル使用メモリ | 74,048 KB |
| 最終ジャッジ日時 | 2025-01-12 13:17:27 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <numeric>
#include <vector>
using lint = long long;
void fail() {
std::cout << -1 << "\n";
std::exit(0);
}
void solve() {
int n;
std::cin >> n;
std::vector<lint> xs(n), ys(n);
for (auto& x : xs) std::cin >> x;
for (auto& y : ys) std::cin >> y;
auto xsum = std::accumulate(xs.begin(), xs.end(), 0LL);
auto ysum = std::accumulate(ys.begin(), ys.end(), 0LL);
if (n == 2) {
if (xsum != ysum) fail();
std::cout << std::abs(xs[0] - ys[0]) << "\n";
return;
}
if (xsum < ysum || (xsum - ysum) % (n - 2) != 0) fail();
auto ope = (xsum - ysum) / (n - 2);
lint need = 0;
for (int i = 0; i < n; ++i) {
xs[i] -= ope;
if (xs[i] > ys[i] || (ys[i] - xs[i]) % 2 != 0) fail();
need += (ys[i] - xs[i]) / 2;
}
if (need != ope) fail();
std::cout << ope << "\n";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}