結果

問題 No.1008 Bench Craftsman
ユーザー ttttan2ttttan2
提出日時 2020-03-07 10:15:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 3,182 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 166,824 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-22 12:32:50
合計ジャッジ時間 4,578 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 106 ms
8,064 KB
testcase_06 AC 28 ms
6,912 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 61 ms
5,376 KB
testcase_10 AC 101 ms
8,108 KB
testcase_11 AC 102 ms
8,064 KB
testcase_12 AC 100 ms
8,064 KB
testcase_13 AC 98 ms
8,192 KB
testcase_14 AC 103 ms
8,192 KB
testcase_15 AC 34 ms
6,528 KB
testcase_16 AC 102 ms
8,064 KB
testcase_17 AC 35 ms
6,656 KB
testcase_18 AC 102 ms
8,192 KB
testcase_19 AC 102 ms
8,192 KB
testcase_20 AC 32 ms
5,888 KB
testcase_21 AC 34 ms
5,632 KB
testcase_22 AC 55 ms
5,632 KB
testcase_23 AC 75 ms
6,912 KB
testcase_24 AC 73 ms
6,528 KB
testcase_25 AC 29 ms
6,272 KB
testcase_26 AC 23 ms
5,760 KB
testcase_27 AC 46 ms
5,376 KB
testcase_28 AC 53 ms
6,272 KB
testcase_29 AC 85 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-9;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;cin>>n>>m;
    ll a[n+1];
    rep(i,1,n+1)cin>>a[i];
    ll x[m],w[m];
    ll s[n+1];
    fill(s,s+n+1,0);
    ll sum=0;
    rep(i,0,m){
        cin>>x[i]>>w[i];
        s[x[i]]+=w[i];
        sum+=w[i];
    }
    rep(i,1,n+1){
        if(s[i]>=a[i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    int rr=0;
    rep(i,1,n+1){
        if(sum>=a[i]){
            rr=1;
            break;
        }
    }
    if(rr==0){
        cout<<0<<endl;
        return 0;
    }
    ll u=100001,d=0;
    while(u-d>1){
        ll mid=(u+d)/2;
        
        ll sl[n+2],sr[n+1];
        fill(sl,sl+n+2,0);
        fill(sr,sr+n+2,0);
        rep(i,0,m){
            ll r=x[i]+w[i]/mid;
            ll l=x[i]-w[i]/mid;
            if(l<=1)l=1;
            if(r>=n)r=n;
            sl[l-1]+=mid;
            sl[x[i]-1]-=mid;
            sr[x[i]+1]-=mid;
            sr[r+1]+=mid;
        }
        rep(i,1,n+2)sr[i]+=sr[i-1];
        rrep(i,n,0)sl[i]+=sl[i+1];
        rep(i,0,m){
            ll r=x[i]+w[i]/mid;
            ll l=x[i]-w[i]/mid;
            if(l<=1)l=1;
            if(r>=n)r=n;
            sl[l-1]+=(x[i]-l)*mid;
            sr[r+1]+=(r-x[i])*mid;
            sr[l]+=w[i];
            sr[r+1]-=w[i];
        }
        rep(i,1,n+2)sr[i]+=sr[i-1];
        rrep(i,n,0)sl[i]+=sl[i+1];
        int t=0;
        rep(i,1,n+1){
            if(sr[i]+sl[i]>=a[i]){
                t=1;
                break;
            }
        }
        if(t)d=mid;
        else u=mid;
    }
    cout<<u<<endl;
}






0