結果

問題 No.1008 Bench Craftsman
ユーザー totori_nyaatotori_nyaa
提出日時 2020-03-06 23:40:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,842 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 174,204 KB
実行使用メモリ 7,556 KB
最終ジャッジ日時 2024-04-22 10:47:08
合計ジャッジ時間 8,316 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,m;
    cin>>n>>m;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    array<ll,2> x[n];
    for(int i=0;i<m;i++){
        int t,h;
        cin>>t>>h;
        t--;
        if(a[t] <= h){
            cout << -1 << endl;
            return 0;
        }
        x[i] = {t,h};
    }
    sort(x,x+m);
    ll low = -1,up=1e9+10;
    while(up-low>1){
        ll mid = (up+low)/2;
        priority_queue<ll> la;
        priority_queue<ll,vector<ll>,greater<ll>> sm;
        ll sum = 0;
        ll inc = 0;
        for(int i=0;i<m;i++){
            ll ret = x[i][1] - x[i][0]*mid;
            if(ret>=0){
                sum += ret;
                inc++;
            }
            else{
                la.push(ret);
            }
        }
        int now = 0;
        bool pos = true;
        ll dec = 0;
        for(int i=0;i<n;i++){
            if(sum >= a[i]){
                pos = false;
                break;
            }
            while(now<m && i == x[now][0]){
                sm.push(x[now][1] + i*mid);
                dec++;
                now++;
                inc--;
            }
            sum += (inc-dec)*mid;
            while(la.size() && la.top() >= -(i+1)*mid){
                inc++;
                ll p = la.top();
                la.pop();
                sum += p+(i+1)*mid;
            }
            while(sm.size() && sm.top() <= (i+1)*mid){
                dec--;
                ll p = sm.top();
                sm.pop();
                sum -= (i+1)*mid - p;
            }
        }
        //cerr << mid << endl;
        if(pos){
            up = mid;
        }
        else low = mid;

    }
    cout << up << endl;

    

}
0