結果

問題 No.1008 Bench Craftsman
ユーザー finefine
提出日時 2020-03-07 01:03:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,929 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 167,040 KB
実行使用メモリ 6,544 KB
最終ジャッジ日時 2024-04-22 11:39:19
合計ジャッジ時間 4,655 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 105 ms
6,288 KB
testcase_06 AC 27 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 71 ms
5,376 KB
testcase_10 AC 99 ms
6,416 KB
testcase_11 AC 98 ms
6,416 KB
testcase_12 AC 102 ms
6,284 KB
testcase_13 AC 102 ms
6,412 KB
testcase_14 AC 99 ms
6,292 KB
testcase_15 AC 98 ms
6,416 KB
testcase_16 AC 102 ms
6,544 KB
testcase_17 AC 99 ms
6,416 KB
testcase_18 AC 110 ms
6,416 KB
testcase_19 AC 105 ms
6,412 KB
testcase_20 AC 32 ms
5,376 KB
testcase_21 AC 36 ms
5,376 KB
testcase_22 AC 70 ms
5,376 KB
testcase_23 AC 82 ms
5,472 KB
testcase_24 AC 83 ms
5,440 KB
testcase_25 AC 27 ms
5,376 KB
testcase_26 AC 22 ms
5,376 KB
testcase_27 AC 60 ms
5,376 KB
testcase_28 AC 54 ms
5,376 KB
testcase_29 AC 85 ms
6,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;

constexpr ll MAXV = 100000;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector<ll> x(m), w(m);
    for (int i = 0; i < m; ++i) {
        cin >> x[i] >> w[i];
        --x[i];
    }

    ll ng = -1, ok = MAXV + 1;
    while (ok - ng > 1) {
        ll c = (ok + ng) / 2;
        if (c == 0) {
            ll sum = 0;
            for (int i = 0; i < m; ++i) {
                sum += w[i];
            }

            bool f = false;
            for (int i = 0; i < n; ++i) {
                if (sum >= a[i]) {
                    f = true;
                    break;
                }
            }
            (f ? ng : ok) = c;
            continue;
        }

        vector<ll> val(n + 1, 0);
        for (int i = 0; i < m; ++i) {
            ll len = w[i] / c;

            ll i1 = max(x[i] - len, 0LL);
            ll hoge = w[i] % c + c * max(len - x[i], 0LL);
            val[i1] += hoge;
            val[i1 + 1] -= hoge;
            if (x[i] > i1) {
                val[i1 + 1] += c;
                val[x[i] + 1] -= c;
            }
            val[x[i] + 1] -= c;

            ll i2 = x[i] + len;
            if (i2 < n) val[i2 + 1] += c;
            if (i2 + 1 < n) val[i2 + 1] -= w[i] % c;
            if (i2 + 2 < n) val[i2 + 2] += w[i] % c;
        }

        for (int i = 0; i < n; ++i) {
            val[i + 1] += val[i];
        }

        for (int i = 0; i < n; ++i) {
            val[i + 1] += val[i];
        }

        bool f = false;
        for (int i = 0; i < n; ++i) {
            if (val[i] >= a[i]) {
                f = true;
                break;
            }
        }
        (f ? ng : ok) = c;
    }
    cout << (ok > MAXV ? -1 : ok) << "\n";
    return 0;
}
0