結果
問題 |
No.1120 Strange Teacher
|
ユーザー |
|
提出日時 | 2020-07-23 09:26:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 700 bytes |
コンパイル時間 | 609 ms |
コンパイル使用メモリ | 64,896 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 17:21:50 |
合計ジャッジ時間 | 2,638 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 WA * 3 |
ソースコード
#include<iostream> #include<numeric> using namespace std; typedef long long ll; void ng(){ cout << -1 << endl; exit(0); } int main(){ int n; cin >> n; int a[n], b[n]; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; ll asum = accumulate(a, a+n, 0ll); ll bsum = accumulate(b, b+n, 0ll); if(n == 2){ if(asum > bsum) ng(); else cout << bsum-asum << endl; return 0; } if(bsum > asum || (asum-bsum)%(n-2) > 0) ng(); ll ans = (asum-bsum)/(n-2); for(int i = 0; i < n; i++){ if(a[i]-ans > b[i] || (b[i]-a[i]+ans)%2) ng(); } cout << ans << endl; return 0; }