結果

問題 No.1120 Strange Teacher
ユーザー ぷらぷら
提出日時 2020-07-22 22:02:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 2,579 ms
コンパイル使用メモリ 167,620 KB
実行使用メモリ 4,696 KB
最終ジャッジ日時 2023-09-04 20:22:45
合計ジャッジ時間 5,286 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 7 ms
4,384 KB
testcase_04 AC 60 ms
4,560 KB
testcase_05 AC 60 ms
4,536 KB
testcase_06 AC 59 ms
4,568 KB
testcase_07 AC 60 ms
4,576 KB
testcase_08 AC 59 ms
4,636 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 60 ms
4,696 KB
testcase_11 AC 60 ms
4,516 KB
testcase_12 AC 60 ms
4,556 KB
testcase_13 AC 60 ms
4,588 KB
testcase_14 AC 60 ms
4,528 KB
testcase_15 AC 60 ms
4,636 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 66 ms
4,512 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 51 ms
4,516 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    vector<int>B(N);
    int sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum+=A[i];
    }
    int sum2 = 0;
    for(int i = 0; i < N; i++) {
        cin >> B[i];
        sum2+=B[i];
    }
    if(N == 2) {
        cout << abs(A[0]-B[0]) << endl;
        return 0;
    }
    // 190 185
    if(abs(sum-sum2)%(N-2) == 0 && sum >= sum2) {
        int MA = (sum-sum2)/(N-2);
        int ans = 0;
        for(int i = 0; i < N; i++) {
            if(A[i]-MA < B[i]) {
                if((B[i]-(A[i]-MA))/2 > MA) {
                    cout << -1 << endl;
                    return 0;
                }
                ans+=(B[i]-(A[i]-MA))/2;
            }
        }
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }
}
0