結果

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

ソースコード

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(n==2){
        if(a[0] + a[1]==b[0] + b[1]){
            cout << max(b[1] - a[1],a[1] - b[1]) << endl; 
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    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