結果

問題 No.1008 Bench Craftsman
ユーザー chielochielo
提出日時 2020-03-06 23:32:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,442 bytes
コンパイル時間 3,454 ms
コンパイル使用メモリ 207,216 KB
実行使用メモリ 20,544 KB
最終ジャッジ日時 2024-04-22 10:43:54
合計ジャッジ時間 7,683 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 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 WA -
testcase_05 TLE -
testcase_06 AC 226 ms
7,372 KB
testcase_07 WA -
testcase_08 AC 121 ms
7,196 KB
testcase_09 AC 1,423 ms
20,544 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 578 ms
10,120 KB
testcase_21 AC 825 ms
8,892 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 278 ms
7,076 KB
testcase_26 AC 242 ms
7,072 KB
testcase_27 AC 1,972 ms
20,312 KB
testcase_28 AC 1,223 ms
13,044 KB
testcase_29 TLE -
権限があれば一括ダウンロードができます

ソースコード

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;
}

std::vector<std::tuple<int, ll, ll>> pt;
bool check(ll c) {
    if(c <= 0) {
        return std::accumulate(w, w + m, 0ll) <= *std::min_element(a + 1, a + n + 1);
    }
    pt.clear();
    for(int j = 0; j < m; ++j) {
        ll u = w[j] / c + x[j];
        ll v = x[j] - w[j] / c;
        pt.emplace_back(v, c, w[j] - c * x[j]);
        pt.emplace_back(x[j], -c, -(w[j] - c * x[j]) + w[j]);
        pt.emplace_back(x[j] + 1, -c, w[j] + c * x[j] - w[j]);
        pt.emplace_back(u + 1, c, -(w[j] + c * x[j]));
    }
    std::sort(pt.begin(), pt.end());
    int j = 0;
    ll u = 0, v = 0;
    for(int i = 1; i <= n; ++i) {
        while(j < pt.size() && std::get<0>(pt[j]) <= i) {
            u += std::get<1>(pt[j]);
            v += std::get<2>(pt[j]);
            j += 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 = 1e18;
    while(r - l > 1) {
        ll mid = (l + r) / 2;
        if(check(mid))
            r = mid;
        else
            l = mid;
    }
    printf("%lld\n", r < 1e18 ? r : -1);
    return 0;
}
0