結果

問題 No.1008 Bench Craftsman
ユーザー ShibuyapShibuyap
提出日時 2020-03-06 22:35:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,259 bytes
コンパイル時間 1,626 ms
コンパイル使用メモリ 169,860 KB
実行使用メモリ 9,332 KB
最終ジャッジ日時 2024-04-22 09:41:07
合計ジャッジ時間 25,920 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1,548 ms
9,204 KB
testcase_06 AC 142 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 857 ms
8,420 KB
testcase_10 AC 1,432 ms
9,328 KB
testcase_11 AC 1,591 ms
9,196 KB
testcase_12 AC 1,509 ms
9,328 KB
testcase_13 AC 1,298 ms
9,332 KB
testcase_14 AC 1,332 ms
9,204 KB
testcase_15 WA -
testcase_16 AC 1,351 ms
9,200 KB
testcase_17 WA -
testcase_18 AC 1,499 ms
9,328 KB
testcase_19 AC 1,296 ms
9,200 KB
testcase_20 AC 337 ms
5,376 KB
testcase_21 AC 448 ms
5,376 KB
testcase_22 AC 1,146 ms
7,760 KB
testcase_23 AC 1,204 ms
8,388 KB
testcase_24 AC 1,253 ms
8,360 KB
testcase_25 AC 192 ms
5,376 KB
testcase_26 AC 159 ms
5,376 KB
testcase_27 AC 900 ms
7,644 KB
testcase_28 AC 671 ms
6,356 KB
testcase_29 AC 1,216 ms
8,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

int main() {
    int n, m;
    cin >> n >> m;
    ll a[n];
    rep(i,n)cin >> a[i];
    ll x[m], w[m];
    rep(i,m){
        cin >> x[i] >> w[i];
        x[i]--;
    }

    ll mi = 1001001001;
    ll ma = 0;
    rep(i,m){
        if(w[i] >= a[x[i]]){
            cout << "-1" << endl;
            return 0;
        }
        ma += w[i];
    }
    rep(i,n)mi = min(mi, a[i]);

    if(mi > ma){
        cout << 0 << endl;
        return 0;
    }

    ll l = 0;
    ll r = 1001001001;

    while(l + 1 < r){
        ll c = (l + r) / 2;
        priority_queue<P, vector<P>, greater<P>> que1, que2, que3;
        rep(i,m){
            ll d = w[i] / c;
            P p;
            p.first = max(x[i] - d, (ll)0);
            p.second = i;
            que1.push(p);
            p.first = x[i];
            que2.push(p);
            p.first = x[i] + d;
            que3.push(p);
        }

        int flag = 0;
        ll cnt1 = 0;
        ll cnt2 = 0;

        ll now = 0;
        rep(i,n){
            now += c * cnt1;
            now -= c * cnt2;

            while(que1.size() && que1.top().first <= i){
                P p = que1.top();
                que1.pop();
                now += w[p.second];
                now -= c * (x[p.second] - (ll)i);
                cnt1++;
            }

            while(que2.size() && que2.top().first <= i){
                cnt1--;
                cnt2++;
                que2.pop();
            }

            if(now >= a[i]){
                flag = 1;
                break;
            }

            while(que3.size() && que3.top().first <= i){
                P p = que3.top();
                que3.pop();
                now -= w[p.second];
                now += c * ((ll)i - x[p.second]);
                cnt2--;
            }
            
            

        }


        if(flag == 0){
            r = c;
        }else{
            l = c;
        }
    }
    
    cout << r << endl;
    return 0;
}
 

 
0