結果

問題 No.1008 Bench Craftsman
ユーザー betrue12betrue12
提出日時 2020-03-06 22:37:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,233 bytes
コンパイル時間 2,337 ms
コンパイル使用メモリ 203,100 KB
実行使用メモリ 5,012 KB
最終ジャッジ日時 2023-08-04 12:08:38
合計ジャッジ時間 6,343 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 154 ms
4,948 KB
testcase_06 AC 54 ms
4,484 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 94 ms
4,380 KB
testcase_10 AC 145 ms
4,832 KB
testcase_11 AC 144 ms
4,896 KB
testcase_12 AC 145 ms
5,012 KB
testcase_13 AC 144 ms
4,876 KB
testcase_14 AC 144 ms
4,844 KB
testcase_15 AC 142 ms
4,952 KB
testcase_16 AC 141 ms
4,888 KB
testcase_17 AC 140 ms
4,972 KB
testcase_18 AC 142 ms
4,976 KB
testcase_19 AC 148 ms
4,900 KB
testcase_20 AC 53 ms
4,376 KB
testcase_21 AC 56 ms
4,376 KB
testcase_22 AC 92 ms
4,376 KB
testcase_23 AC 115 ms
4,424 KB
testcase_24 AC 113 ms
4,420 KB
testcase_25 AC 51 ms
4,376 KB
testcase_26 AC 40 ms
4,380 KB
testcase_27 AC 76 ms
4,376 KB
testcase_28 AC 81 ms
4,500 KB
testcase_29 AC 122 ms
4,952 KB
権限があれば一括ダウンロードができます

ソースコード

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> imos(N+2);
        for(int i=0; i<M; i++){
            int d = W[i]/C;
            int L = max(0, X[i]-d);
            int R = min(N-1, X[i]+d);
            int64_t VL = W[i] - (X[i]-L)*C;
            int64_t VR = W[i] - (R-X[i])*C;
            imos[L] += VL;
            imos[L+1] += C - VL;
            imos[X[i]+1] += -2*C;
            imos[R+1] += C - VR;
            imos[R+2] += VR;
        }
        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++) if(imos[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