結果

問題 No.1008 Bench Craftsman
ユーザー betrue12betrue12
提出日時 2020-03-06 22:37:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 1,233 bytes
コンパイル時間 2,408 ms
コンパイル使用メモリ 199,256 KB
実行使用メモリ 5,472 KB
最終ジャッジ日時 2024-04-22 09:44:56
合計ジャッジ時間 6,988 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 174 ms
5,376 KB
testcase_06 AC 61 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 105 ms
5,376 KB
testcase_10 AC 161 ms
5,376 KB
testcase_11 AC 161 ms
5,376 KB
testcase_12 AC 161 ms
5,376 KB
testcase_13 AC 162 ms
5,376 KB
testcase_14 AC 161 ms
5,472 KB
testcase_15 AC 160 ms
5,376 KB
testcase_16 AC 159 ms
5,376 KB
testcase_17 AC 157 ms
5,376 KB
testcase_18 AC 159 ms
5,376 KB
testcase_19 AC 161 ms
5,376 KB
testcase_20 AC 59 ms
5,376 KB
testcase_21 AC 62 ms
5,376 KB
testcase_22 AC 103 ms
5,376 KB
testcase_23 AC 128 ms
5,376 KB
testcase_24 AC 126 ms
5,376 KB
testcase_25 AC 57 ms
5,376 KB
testcase_26 AC 45 ms
5,376 KB
testcase_27 AC 85 ms
5,376 KB
testcase_28 AC 92 ms
5,376 KB
testcase_29 AC 136 ms
5,376 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