結果
問題 | No.1008 Bench Craftsman |
ユーザー | mugen_1337 |
提出日時 | 2020-03-07 17:44:20 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,799 bytes |
コンパイル時間 | 1,601 ms |
コンパイル使用メモリ | 173,488 KB |
実行使用メモリ | 18,480 KB |
最終ジャッジ日時 | 2024-04-23 04:41:20 |
合計ジャッジ時間 | 28,743 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,816 KB |
testcase_01 | AC | 3 ms
6,944 KB |
testcase_02 | AC | 3 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,944 KB |
testcase_04 | WA | - |
testcase_05 | AC | 1,815 ms
18,480 KB |
testcase_06 | AC | 352 ms
12,536 KB |
testcase_07 | WA | - |
testcase_08 | AC | 5 ms
6,940 KB |
testcase_09 | AC | 280 ms
8,228 KB |
testcase_10 | AC | 1,848 ms
18,336 KB |
testcase_11 | AC | 1,861 ms
18,288 KB |
testcase_12 | AC | 1,858 ms
18,468 KB |
testcase_13 | AC | 1,836 ms
18,348 KB |
testcase_14 | AC | 1,886 ms
18,348 KB |
testcase_15 | AC | 39 ms
8,448 KB |
testcase_16 | AC | 1,773 ms
18,356 KB |
testcase_17 | AC | 40 ms
8,448 KB |
testcase_18 | WA | - |
testcase_19 | TLE | - |
testcase_20 | AC | 664 ms
11,268 KB |
testcase_21 | AC | 682 ms
11,012 KB |
testcase_22 | AC | 987 ms
11,128 KB |
testcase_23 | AC | 1,369 ms
14,416 KB |
testcase_24 | AC | 1,249 ms
13,216 KB |
testcase_25 | AC | 372 ms
12,032 KB |
testcase_26 | AC | 314 ms
11,648 KB |
testcase_27 | AC | 735 ms
9,792 KB |
testcase_28 | AC | 988 ms
13,276 KB |
testcase_29 | AC | 1,514 ms
16,140 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define INF 1000000000 #define mod 1000000007 using ll=long long; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;} int n,m; vector<ll> a; vector<vector<ll>> w(100001); bool f(ll c){ vector<ll> cost(n,0); // dec { vector<vector<ll>> in(n); vector<vector<ll>> out(n); ll sum=0,cnt=0; rep(i,n){ for(auto x:w[i]){ in[i].push_back(x); out[min(n-1,i+(int)(x/c))].push_back(x%c); } } rep(i,n){ for(auto x:in[i]){ sum+=x; cnt++; } cost[i]+=sum; for(auto x:out[i]){ cnt--; sum-=x; } sum-=c*cnt; } } //inc { vector<vector<ll>> in(n); vector<vector<ll>> out(n); ll sum=0,cnt=0; rep(i,n){ for(auto x:w[i]){ in[i].push_back(x); out[max(0,i-(int)(x/c))].push_back(x%c); } } for(int i=n-1;i>=0;i--){ for(auto x:in[i]){ sum+=x; cnt++; } cost[i]+=sum; for(auto x:out[i]){ cnt--; sum-=x; } sum-=c*cnt; } } // cout<<endl; // debug(cost); rep(i,n){ ll sum=0; for(auto x:w[i]) sum+=x; if(cost[i]-sum>a[i]){ // cout<<c<<" false\n"; return false; } } // cout<<c<<" true\n"; return true; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cin>>n>>m; a.resize(n);w.resize(n); rep(i,n) cin>>a[i]; rep(i,m){ int j,x;cin>>j>>x;j--; w[j].push_back(x); } rep(i,n){ ll sum=0; for(auto x:w[i]) sum+=x; if(sum>a[i]){ cout<<-1<<endl; return 0; } } { ll sum=0; rep(i,n){ for(auto x:w[i]) sum+=x; } if(*min_element(ALL(a))>=sum){ cout<<0<<endl; return 0; } } ll lw=1,hi=LINF,ans=LINF; while(lw<=hi){ ll mid=(lw+hi)/2; if(f(mid)){ chmin(ans,mid); hi=mid-1; }else{ lw=mid+1; } } cout<<ans<<endl; return 0; }