結果

問題 No.1008 Bench Craftsman
ユーザー betrue12betrue12
提出日時 2020-03-06 22:18:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,322 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 200,448 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 08:32:15
合計ジャッジ時間 6,848 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 7 ms
6,940 KB
testcase_09 AC 84 ms
6,940 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 155 ms
6,940 KB
testcase_16 WA -
testcase_17 AC 158 ms
6,940 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 75 ms
6,940 KB
testcase_26 AC 59 ms
6,944 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    vector<int> X(M), W(M);
    for(int i=0; i<M; i++) cin >> X[i] >> W[i], X[i]--;

    int64_t sum = accumulate(W.begin(), W.end(), 0LL);
    if(sum < *min_element(A.begin(), A.end())){
        cout << 0 << endl;
        return 0;
    }

    auto check = [&](int64_t C)->bool{
        vector<int64_t> num(N), imos(N+1);
        for(int i=0; i<M; i++){
            int d = W[i]/C;
            if(d == 0){
                num[X[i]] += W[i];
                continue;
            }
            int L = max(0, X[i]-d);
            int R = min(N-1, X[i]+d);
            num[L] += W[i] - (X[i]-L)*C;
            num[R] += W[i] - (R-X[i])*C;
            imos[L+1] += C;
            imos[X[i]+1] += -2*C;
            imos[R+1] += C;
        }
        for(int t=0; t<2; t++) for(int i=1; i<=N; i++) imos[i] += imos[i-1];
        for(int i=0; i<N; i++){
            num[i] += imos[i];
            if(num[i] >= A[i]) return false;
        }
        return true;
    };

    int ok = 1e9, ng = 0;
    while(ok-ng>1){
        int mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    int ans = ok;
    if(ans == 1e9) ans = -1;
    cout << ans << endl;
    return 0;
}
0