結果

問題 No.1008 Bench Craftsman
ユーザー finefine
提出日時 2020-03-06 23:59:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,708 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 165,764 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 10:58:39
合計ジャッジ時間 4,781 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 63 ms
6,944 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 24 ms
6,940 KB
testcase_26 AC 20 ms
6,944 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const 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);
            val[i1] += w[i] % c + c * max(len - x[i], 0LL);
            if (len > 0) val[i1 + 1] += c;

            val[x[i] + 1] += -c * 2;

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

                if (i2 + 1 < n) {
                    val[i2 + 2] += w[i] % c;
                }
            }
        }

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