結果

問題 No.1008 Bench Craftsman
ユーザー mgingin142857mgingin142857
提出日時 2020-03-06 22:38:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,636 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 169,632 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2024-04-22 09:45:58
合計ジャッジ時間 7,750 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
6,528 KB
testcase_01 AC 15 ms
6,528 KB
testcase_02 AC 13 ms
6,400 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 13 ms
6,528 KB
testcase_08 AC 32 ms
6,784 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 238 ms
9,608 KB
testcase_16 WA -
testcase_17 AC 236 ms
9,728 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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<<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;
}
0