結果
問題 |
No.1120 Strange Teacher
|
ユーザー |
|
提出日時 | 2020-07-22 21:29:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 62 ms / 1,000 ms |
コード長 | 1,194 bytes |
コンパイル時間 | 721 ms |
コンパイル使用メモリ | 90,552 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 13:37:40 |
合計ジャッジ時間 | 2,699 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> #include<complex> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF (1<<29) #define LINF (1LL<<60) #define EPS (1e-10) #define PI 3.1415926535897932384626433832795028 typedef long long Int; typedef pair<Int, Int> P; typedef long double Real; typedef complex<Real> CP; void ok(){ cout << "Yes" << endl; exit(0); } void ng(){ cout << "-1" << endl; exit(0); } Int n; Int a[110000], b[110000]; Int ans; int main(){ cin >> n; Int suma = 0, 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)ng(); cout << abs(a[0] - b[0]) << endl; return 0; } if((suma - sumb) % (n-2) != 0)ng(); if(suma < sumb)ng(); Int cnt = (suma - sumb) / (n-2); for(int i = 0;i < n;i++){ Int dif = b[i] - (a[i] - cnt); if(dif < 0)ng(); if(dif % 2 == 1)ng(); ans += dif / 2; } cout << ans << endl; return 0; }