結果

問題 No.1008 Bench Craftsman
ユーザー chielochielo
提出日時 2020-03-06 23:56:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,365 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 195,816 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-04-22 10:57:38
合計ジャッジ時間 5,319 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 108 ms
7,296 KB
testcase_06 AC 29 ms
6,272 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 9 ms
5,376 KB
testcase_09 AC 73 ms
5,376 KB
testcase_10 AC 106 ms
7,296 KB
testcase_11 AC 105 ms
7,168 KB
testcase_12 AC 104 ms
7,296 KB
testcase_13 AC 106 ms
7,424 KB
testcase_14 AC 105 ms
7,296 KB
testcase_15 AC 105 ms
7,296 KB
testcase_16 AC 102 ms
7,296 KB
testcase_17 AC 104 ms
7,424 KB
testcase_18 AC 106 ms
7,168 KB
testcase_19 AC 102 ms
7,296 KB
testcase_20 AC 33 ms
5,504 KB
testcase_21 AC 37 ms
5,376 KB
testcase_22 AC 65 ms
5,376 KB
testcase_23 AC 81 ms
6,272 KB
testcase_24 AC 78 ms
6,016 KB
testcase_25 AC 29 ms
5,888 KB
testcase_26 AC 24 ms
5,376 KB
testcase_27 AC 55 ms
5,376 KB
testcase_28 AC 54 ms
5,888 KB
testcase_29 AC 87 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
const int maxn = 2e5 + 3;

int n, m, x[maxn];
ll a[maxn], w[maxn];

ll ceildiv(ll a, ll b) {
    return a % b ? a / b + 1 : a / b;
}

ll pt[maxn][2];
bool check(ll c) {
    if(c <= 0) {
        return std::accumulate(w, w + m, 0ll) <= *std::min_element(a + 1, a + n + 1);
    }
    for(int i = 1; i <= n + 1; ++i)
        pt[i][0] = pt[i][1] = 0;
    for(int j = 0; j < m; ++j) {
        ll u = w[j] / c + x[j];
        ll v = x[j] - w[j] / c;
        pt[std::max(1ll, v)][0] += c;
        pt[std::max(1ll, v)][1] += w[j] - c * x[j];
        pt[x[j]][0] += -c - c;
        pt[x[j]][1] += w[j] + c * x[j] - (w[j] - c * x[j]);
        pt[std::min(n + 1ll, u + 1)][0] += c;
        pt[std::min(n + 1ll, u + 1)][1] += -(w[j] + c * x[j]);
    }
    ll u = 0, v = 0;
    for(int i = 1; i <= n; ++i) {
        u += pt[i][0];
        v += pt[i][1];
        if(u * (ll)i + v >= a[i])
            return false;
    }
    return true;
}

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)
        scanf("%lld", a + i);
    for(int i = 0; i < m; ++i)
        scanf("%d%lld", x + i, w + i);
    ll l = -1, r = 1e10;
    while(r - l > 1) {
        ll mid = (l + r) / 2;
        if(check(mid))
            r = mid;
        else
            l = mid;
    }
    printf("%lld\n", r < 1e10 ? r : -1);
    return 0;
}
0