結果

問題 No.1120 Strange Teacher
ユーザー DriceDrice
提出日時 2020-07-22 21:45:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 1,000 ms
コード長 1,149 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 32,356 KB
実行使用メモリ 4,592 KB
最終ジャッジ日時 2023-09-04 17:03:16
合計ジャッジ時間 2,115 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 24 ms
4,512 KB
testcase_05 AC 24 ms
4,516 KB
testcase_06 AC 28 ms
4,508 KB
testcase_07 AC 25 ms
4,592 KB
testcase_08 AC 25 ms
4,500 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 23 ms
4,544 KB
testcase_11 AC 24 ms
4,504 KB
testcase_12 AC 24 ms
4,496 KB
testcase_13 AC 24 ms
4,452 KB
testcase_14 AC 24 ms
4,384 KB
testcase_15 AC 24 ms
4,496 KB
testcase_16 AC 24 ms
4,492 KB
testcase_17 AC 24 ms
4,500 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 25 ms
4,592 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 21 ms
4,516 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
long long a[100005];
long long b[100005];

long long min(long long a,long long b){ return a>b?b:a; }

int main(){
    int n;
    scanf("%d",&n);
    long long sumA = 0, sumB = 0;
    for(int i = 1; i <= n; i++){
        scanf("%lld",&a[i]);
        sumA += a[i];
    }
    for(int i = 1; i <= n; i++){
        scanf("%lld",&b[i]);
        sumB += b[i];
    }
    long long add = 2-n, diff = sumB-sumA;
    if(n==2){
        if(diff!=0) printf("-1\n");
        else{
            long long gap = a[1]-b[1];
            if(gap<0) gap *= -1;
            printf("%lld\n",gap);
        }
    }
    else if(diff%add || diff>0) printf("-1\n");
    else{
        long long time = diff/add;
        long long have = time*2;
        int ok = 1;
        for(int i = 1; i <= n; i++){
            a[i] -= time;
            //printf("a[%d] = %lld\n",i,a[i]);
            if(a[i]>b[i]) ok = 0;
            else{
                long long gap = b[i]-a[i];
                if(gap%2 || gap>have) ok = 0;
                else have -= gap;
            }
        }
        if(ok) printf("%lld\n",time);
        else printf("-1\n");
    }
    return 0;
}
0