結果

問題 No.1008 Bench Craftsman
ユーザー mgingin142857mgingin142857
提出日時 2020-03-06 22:54:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 374 ms / 2,000 ms
コード長 1,637 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 168,960 KB
実行使用メモリ 9,732 KB
最終ジャッジ日時 2024-04-22 10:06:42
合計ジャッジ時間 9,662 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
6,400 KB
testcase_01 AC 24 ms
6,400 KB
testcase_02 AC 19 ms
6,528 KB
testcase_03 AC 24 ms
6,400 KB
testcase_04 AC 23 ms
6,272 KB
testcase_05 AC 374 ms
9,732 KB
testcase_06 AC 100 ms
8,320 KB
testcase_07 AC 19 ms
6,400 KB
testcase_08 AC 51 ms
6,672 KB
testcase_09 AC 297 ms
8,052 KB
testcase_10 AC 354 ms
9,600 KB
testcase_11 AC 362 ms
9,604 KB
testcase_12 AC 352 ms
9,604 KB
testcase_13 AC 364 ms
9,732 KB
testcase_14 AC 353 ms
9,684 KB
testcase_15 AC 352 ms
9,628 KB
testcase_16 AC 355 ms
9,600 KB
testcase_17 AC 352 ms
9,564 KB
testcase_18 AC 358 ms
9,608 KB
testcase_19 AC 354 ms
9,476 KB
testcase_20 AC 121 ms
7,888 KB
testcase_21 AC 136 ms
7,920 KB
testcase_22 AC 253 ms
8,184 KB
testcase_23 AC 299 ms
8,936 KB
testcase_24 AC 300 ms
8,688 KB
testcase_25 AC 100 ms
8,064 KB
testcase_26 AC 86 ms
7,624 KB
testcase_27 AC 220 ms
7,816 KB
testcase_28 AC 196 ms
8,364 KB
testcase_29 AC 298 ms
9,084 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