結果
| 問題 |
No.1120 Strange Teacher
|
| コンテスト | |
| ユーザー |
poohbear
|
| 提出日時 | 2020-07-23 21:14:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 100 ms / 1,000 ms |
| コード長 | 1,145 bytes |
| コンパイル時間 | 2,894 ms |
| コンパイル使用メモリ | 194,340 KB |
| 最終ジャッジ日時 | 2025-01-12 04:32:10 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
int main(){
int n;
cin >> n;
vector<ll>a(n),b(n);
ll sa=0,sb=0;
rep(i,n){
cin>>a[i];
sa+=a[i];
}
rep(i,n){
cin>>b[i];
sb+=b[i];
}
if(sa<sb){
cout << -1 << endl;
return 0;
}
if(n==2){
if((sa+sb)%2==0){
cout << abs(a[0]-b[0]) << endl;
return 0;
}
else{
cout << -1 << endl;
return 0;
}
}
if((sa-sb)%(n-2)!=0){
cout << -1 << endl;
return 0;
}
ll c = (sa-sb)/(n-2);
rep(i,n){
ll t = b[i]-(a[i]-c);
if(t<0||t%2==1){
cout << -1 << endl;
return 0;
}
}
cout << c << endl;
return 0;
}
poohbear