結果

問題 No.1008 Bench Craftsman
ユーザー nrvftnrvft
提出日時 2020-03-06 23:40:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,948 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 209,552 KB
実行使用メモリ 16,488 KB
最終ジャッジ日時 2024-04-22 10:44:42
合計ジャッジ時間 13,902 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 574 ms
16,488 KB
testcase_06 RE -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 621 ms
16,384 KB
testcase_11 AC 668 ms
16,384 KB
testcase_12 AC 701 ms
16,256 KB
testcase_13 AC 598 ms
16,360 KB
testcase_14 AC 689 ms
16,384 KB
testcase_15 AC 545 ms
16,384 KB
testcase_16 AC 600 ms
16,356 KB
testcase_17 AC 641 ms
16,300 KB
testcase_18 AC 712 ms
16,312 KB
testcase_19 AC 666 ms
16,296 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N,M;cin>>N>>M;
    vl A(N);
    rep(i, N) cin >> A[i];
    vc<pair<ll,ll>> pp(M);
    rep(i,M){
        ll x, w;
        cin >> x >> w;
        x--;
        pp[i] = {x, w};
    }
    sort(all(pp));
    vl Xcnt(N);
    rep(i, N) Xcnt[pp[i].first]++;

    //c=0でokなら返す
    ll sum = 0;
    rep(i,M){
        sum += pp[i].second;
    }
    bool ok0 = true;
    rep(i,N){
        if(sum>=A[i]){
            ok0 = false;
            break;
        }
    }
    if(ok0){
        cout << 0 << endl;
        return 0;
    }

    //二分探索
    ll ng = 0, ok = 1e9;
    while(ok-ng>1){
        bool isok = true;
        ll mid = (ok + ng) / 2;

        vvc<pair<ll,ll>> add(N), del(N);
        for(auto p:pp){
            ll x, w;
            tie(x, w) = p;
            ll r = w / mid;
            add[max(0ll, x - r)].eb(x,w);
            del[min(N - 1, x + r)].eb(x,w);
        }
        // cout << "add" << endl;
        // rep(i,N){
        //     cout << i << endl;
        //     for (auto p : add[i]) cout << p.first << " " << p.second << " ";
        //     cout << endl;
        // }
        // cout << "del" << endl;
        // rep(i,N){
        //     cout << i << endl;
        //     for (auto p : del[i]) cout << p.first << " " << p.second << " ";
        //     cout << endl<<endl;
        // }

        ll cnt = 0, val = 0;
        rep(i,N){
            val += cnt * mid;
            for(auto p:add[i]){
                ll x, w;
                tie(x, w) = p;
                cnt++;
                val += w - (x - i) * mid;
            }
            if(val>=A[i]){
                isok = false;
                break;
            }
            for(auto p:del[i]){
                ll x, w;
                tie(x, w) = p;
                cnt++;
                val -= w - (i - x) * mid;
            }
            cnt -= Xcnt[i] * 2;
        }
        (isok ? ok : ng) = mid;
    }
    if(ok==1e9){
        cout << -1 << endl;
        return 0;
    }
    cout << ok << endl;
}
0