結果

問題 No.1008 Bench Craftsman
ユーザー mgingin142857mgingin142857
提出日時 2020-03-06 22:54:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 403 ms / 2,000 ms
コード長 1,637 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 170,984 KB
実行使用メモリ 9,556 KB
最終ジャッジ日時 2023-08-04 12:30:34
合計ジャッジ時間 10,268 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
6,144 KB
testcase_01 AC 27 ms
6,332 KB
testcase_02 AC 23 ms
6,268 KB
testcase_03 AC 27 ms
6,144 KB
testcase_04 AC 28 ms
6,392 KB
testcase_05 AC 403 ms
9,256 KB
testcase_06 AC 104 ms
8,080 KB
testcase_07 AC 23 ms
6,340 KB
testcase_08 AC 55 ms
6,652 KB
testcase_09 AC 319 ms
7,944 KB
testcase_10 AC 374 ms
9,320 KB
testcase_11 AC 379 ms
9,316 KB
testcase_12 AC 381 ms
9,280 KB
testcase_13 AC 379 ms
9,296 KB
testcase_14 AC 381 ms
9,556 KB
testcase_15 AC 377 ms
9,416 KB
testcase_16 AC 380 ms
9,232 KB
testcase_17 AC 373 ms
9,384 KB
testcase_18 AC 382 ms
9,236 KB
testcase_19 AC 380 ms
9,308 KB
testcase_20 AC 132 ms
7,684 KB
testcase_21 AC 151 ms
7,668 KB
testcase_22 AC 272 ms
7,864 KB
testcase_23 AC 310 ms
8,464 KB
testcase_24 AC 316 ms
8,364 KB
testcase_25 AC 106 ms
7,740 KB
testcase_26 AC 91 ms
7,588 KB
testcase_27 AC 233 ms
7,600 KB
testcase_28 AC 206 ms
8,048 KB
testcase_29 AC 324 ms
8,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<<60;
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+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));
  }
  ll l=-1;
  ll r=INF;
  while(r-l>1){
    VI q(n+2*zure,0);
    bool ng=0;
    ll m=l+(r-l)/2;
    if(m!=0){
    for(i=0;i<v.size();i++){
      q[v[i].fi+1]+=-2*m;
      ll 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;
}
0