結果
問題 |
No.1008 Bench Craftsman
|
ユーザー |
![]() |
提出日時 | 2020-03-06 22:38:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,636 bytes |
コンパイル時間 | 1,559 ms |
コンパイル使用メモリ | 172,496 KB |
実行使用メモリ | 9,736 KB |
最終ジャッジ日時 | 2024-10-14 08:59:27 |
合計ジャッジ時間 | 6,850 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair<ll,ll> P; using VP = vector<P>; using VVP = vector<VP>; using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>; const int inf=1e9+7; const ll INF=1LL<<61; const ll mod=1e9+7; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } int main(){ int i,j; int n,m; cin>>n>>m; int zure=101010; VI a(n+2*zure,INF); vector<P> v; for(i=zure;i<zure+n;i++) cin>>a[i]; for(i=0;i<m;i++){ ll x,w; cin>>x>>w; x--; x+=zure; v.pb(P(x,w)); } int l=-1; int r=inf; while(r-l>1){ VI q(n+2*zure,0); bool ng=0; int m=l+(r-l)/2; if(m!=0){ for(i=0;i<v.size();i++){ q[v[i].fi+1]=-2*m; int wid=v[i].se/m; q[v[i].fi+1+wid]+=m-(v[i].se%m); q[v[i].fi+1+wid+1]+=v[i].se%m; q[v[i].fi+1-wid]+=m-(v[i].se%m); q[v[i].fi+1-wid-1]+=v[i].se%m; } for(i=1;i<n+2*zure;i++){ q[i]=q[i-1]+q[i]; } for(i=1;i<n+2*zure;i++){ q[i]=q[i-1]+q[i]; if(q[i]>=a[i]){ ng=1; break; } } } else{ ll h=0; for(i=0;i<v.size();i++){ h+=v[i].se; } for(i=0;i<n+2*zure;i++){ if(h>=a[i]){ ng=1; break; } } } if(ng) l=m; else r=m; } if(r==inf){ cout<<-1<<endl; return 0; } else cout<<r<<endl; return 0; }