結果

問題 No.1008 Bench Craftsman
ユーザー chocoruskchocorusk
提出日時 2020-03-06 22:21:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,168 bytes
コンパイル時間 1,245 ms
コンパイル使用メモリ 110,964 KB
実行使用メモリ 9,584 KB
最終ジャッジ日時 2024-04-22 08:43:19
合計ジャッジ時間 5,753 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,524 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 7 ms
6,944 KB
testcase_09 AC 57 ms
8,612 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 165 ms
9,352 KB
testcase_16 WA -
testcase_17 AC 162 ms
9,384 KB
testcase_18 AC 163 ms
9,400 KB
testcase_19 AC 163 ms
9,332 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 58 ms
8,980 KB
testcase_26 AC 47 ms
8,396 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, m;
    cin>>n>>m;
    ll a[100010];
    for(int i=0; i<n; i++) cin>>a[i];
    int x[100010];
    ll w[100010];
    for(int i=0; i<m; i++) cin>>x[i]>>w[i], x[i]--;
    ll s0=0;
    for(int i=0; i<m; i++) s0+=w[i];
    bool ok=1;
    for(int i=0; i<n; i++){
        if(s0>=a[i]){
            ok=0; break;
        }
    }
    if(ok){
        cout<<0<<endl;
        return 0;
    }
    const ll INF=100010;
    ll l=0, r=INF;
    auto check=[&](ll c){
        ll s=0;
        for(int i=0; i<m; i++) s+=max(0ll, w[i]-x[i]*c);
        if(s>=a[0]) return false;
        ll s1[100010]={}, s2[100010]={}, d[100010]={}, e[100010]={}, f[100010]={};
        for(int i=0; i<m; i++){
            if(x[i]-w[i]/c>=0){
                ll t=x[i]-w[i]/c;
                s1[t]+=w[i]-abs(t-x[i])*c;
                d[t]++;
            }
        }
        for(int i=0; i<m; i++){
            if(x[i]+w[i]/c<n){
                ll t=x[i]+w[i]/c;
                s2[t]+=w[i]-abs(t-x[i])*c;
                f[t]++;
            }
            e[x[i]]++;
        }
        ll cnt1=0, cnt2=0;
        cnt1+=d[0];
        cnt1-=e[0], cnt2+=e[0];
        cnt2-=f[0];
        s-=s2[0];
        for(int i=1; i<n; i++){
            s+=cnt1*c;
            s-=cnt2*c;
            s+=s1[i];
            if(s>=a[i]) return false;
            cnt1+=d[i];
            cnt1-=e[i], cnt2+=e[i];
            cnt2-=f[i];
            s-=s2[i];
        }
        return true;
    };
    while(r-l>1){
        ll mid=(l+r)/2;
        if(check(mid)) r=mid;
        else l=mid;
    }
    if(r==INF) cout<<-1<<endl;
    else cout<<r<<endl;
	return 0;
}
0