結果

問題 No.1008 Bench Craftsman
ユーザー chocoruskchocorusk
提出日時 2020-03-06 22:25:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 2,211 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 111,488 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-22 08:48:17
合計ジャッジ時間 5,186 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,552 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 6 ms
7,424 KB
testcase_04 AC 7 ms
7,388 KB
testcase_05 AC 190 ms
9,472 KB
testcase_06 AC 59 ms
8,576 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 58 ms
8,576 KB
testcase_10 AC 172 ms
9,432 KB
testcase_11 AC 173 ms
9,472 KB
testcase_12 AC 173 ms
9,472 KB
testcase_13 AC 169 ms
9,428 KB
testcase_14 AC 176 ms
9,600 KB
testcase_15 AC 174 ms
9,344 KB
testcase_16 AC 171 ms
9,452 KB
testcase_17 AC 172 ms
9,352 KB
testcase_18 AC 174 ms
9,492 KB
testcase_19 AC 164 ms
9,484 KB
testcase_20 AC 61 ms
8,192 KB
testcase_21 AC 65 ms
8,320 KB
testcase_22 AC 98 ms
8,704 KB
testcase_23 AC 129 ms
9,088 KB
testcase_24 AC 133 ms
8,868 KB
testcase_25 AC 60 ms
8,448 KB
testcase_26 AC 48 ms
8,192 KB
testcase_27 AC 81 ms
8,448 KB
testcase_28 AC 93 ms
8,576 KB
testcase_29 AC 148 ms
9,216 KB
権限があれば一括ダウンロードができます

ソースコード

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]++;
            }else{
                d[0]++;
            }
        }
        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