結果

問題 No.1120 Strange Teacher
ユーザー pockyny
提出日時 2020-07-22 21:41:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 676 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 66,492 KB
最終ジャッジ日時 2025-01-12 02:26:16
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
typedef long long ll;
ll a[100010],b[100010];
int main(){
    int i; ll n; cin >> n;
    for(i=0;i<n;i++) cin >> a[i];
    for(i=0;i<n;i++) cin >> b[i];
    ll s1 = 0,s2 = 0;
    for(i=0;i<n;i++){
        s1 += a[i]; s2 += b[i];
    }
    if(s1<s2 || (s1 - s2)%(n - 2)!=0){
        cout << -1 << endl;
        return 0;
    }
    ll t = (s1 - s2)/(n - 2),tt = 0;
    for(i=0;i<n;i++){
        if((b[i] - a[i] + t<0) || (b[i] - a[i] + t)&1){
            cout << -1 << endl;
            return 0;
        }
        tt += (b[i] - a[i] + t)/2;
    }
    if(tt==t){
        cout << t << endl;
    }else{
        cout << -1 << endl;
    }
}
0