結果

問題 No.1008 Bench Craftsman
ユーザー mugen_1337mugen_1337
提出日時 2020-10-24 20:53:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,161 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 203,900 KB
実行使用メモリ 9,756 KB
最終ジャッジ日時 2023-09-28 20:55:52
合計ジャッジ時間 9,033 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 351 ms
9,696 KB
testcase_06 AC 130 ms
7,992 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 16 ms
4,376 KB
testcase_09 AC 152 ms
4,532 KB
testcase_10 AC 340 ms
9,704 KB
testcase_11 AC 343 ms
9,756 KB
testcase_12 AC 344 ms
9,696 KB
testcase_13 AC 339 ms
9,700 KB
testcase_14 AC 339 ms
9,704 KB
testcase_15 AC 87 ms
6,100 KB
testcase_16 AC 338 ms
9,700 KB
testcase_17 AC 87 ms
6,192 KB
testcase_18 AC 340 ms
9,648 KB
testcase_19 AC 338 ms
9,696 KB
testcase_20 AC 120 ms
6,736 KB
testcase_21 AC 120 ms
6,080 KB
testcase_22 AC 166 ms
5,488 KB
testcase_23 AC 249 ms
7,716 KB
testcase_24 AC 227 ms
7,052 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 128 ms
4,888 KB
testcase_28 AC 183 ms
7,688 KB
testcase_29 AC 277 ms
8,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1000000000
using ll=long long;
int n,m,x[100010];
ll wsum[100010],a[100010],w[100010];
bool f(ll c){
if(c==0) return true;
vector<ll> in(n,0),ic(n,0),out(n,0),oc(n,0),cost(n,0);
ll sum=0,cnt=0;
rep(i,m){in[x[i]]+=w[i];ic[x[i]]++;out[min(n-1,x[i]+(int)(w[i]/c))]+=w[i]%c;oc[min(n-1,x[i]+(int)(w[i]/c))]++;}
rep(i,n){sum+=in[i];cnt+=ic[i]-oc[i];cost[i]+=sum;sum-=out[i]+c*cnt;}
in.assign(n,0);ic.assign(n,0);out.assign(n,0);oc.assign(n,0);sum=0,cnt=0;
rep(i,m){in[x[i]]+=w[i];ic[x[i]]++;out[max(0,x[i]-(int)(w[i]/c))]+=w[i]%c;oc[max(0,x[i]-(int)(w[i]/c))]++;}
for(int i=n-1;i>=0;i--){sum+=in[i];cnt+=ic[i]-oc[i];cost[i]+=sum;sum-=out[i]+c*cnt;}
rep(i,n)if(cost[i]-wsum[i]>=a[i])return false;
return true;
}
signed main(){
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    rep(i,m){cin>>x[i]>>w[i];x[i]--;wsum[x[i]]+=w[i];}
    rep(i,n)if(wsum[i]>=a[i]){cout<<-1<<endl;return 0;}
    ll sum=0,lw=0,hi=INF,ans=INF;
    rep(i,m) sum+=w[i];
    while(lw<=hi){
        ll M=(lw+hi)/2;
        if(f(M)){
            ans=M;hi=M-1;
        }else lw=M+1;
    }
    cout<<ans<<endl;
}
0