Submission #66740151


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int n, h, m;
    cin >> n >> h >> m;
    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];

    auto chmax = [&](int& x, int y) {
        if (y > x) x = y;
    };

    int ans = 0;
    vector<vector<int>> dp(n + 1, vector<int>(h + 1, -1));
    for (int i = 0; i <= h; i++) dp[0][i] = m;
    for (int i = 1; i <= n; i++) {
        for (int j = h - a[i]; j >= 0; j--) {
            chmax(dp[i][j + a[i]], dp[i - 1][j]);
        } 
        for (int j = h; j >= 0; j--) {
            if (dp[i - 1][j] >= b[i]) {
                chmax(dp[i][j], dp[i - 1][j] - b[i]);
            }
        }
        bool ok = false;
        for (int j = h; j >= 0; j--) if (dp[i][j] >= 0) {
            ans = i;
            ok = true;
            break;
        } 
        if (!ok) break;
    }
    cout << ans << '\n';
    return 0;
}

Submission Info

Submission Time
Task E - Battles in a Row
User liangsheng
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1026 Byte
Status AC
Exec Time 32 ms
Memory 38556 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 40
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 9 ms 22300 KiB
random_02.txt AC 13 ms 25248 KiB
random_03.txt AC 10 ms 15744 KiB
random_04.txt AC 4 ms 10180 KiB
random_05.txt AC 7 ms 13548 KiB
random_06.txt AC 5 ms 8384 KiB
random_07.txt AC 11 ms 23316 KiB
random_08.txt AC 15 ms 27600 KiB
random_09.txt AC 12 ms 17884 KiB
random_10.txt AC 5 ms 14296 KiB
random_11.txt AC 12 ms 24152 KiB
random_12.txt AC 12 ms 16580 KiB
random_13.txt AC 2 ms 5136 KiB
random_14.txt AC 7 ms 9920 KiB
random_15.txt AC 18 ms 29880 KiB
random_16.txt AC 5 ms 12840 KiB
random_17.txt AC 7 ms 10164 KiB
random_18.txt AC 6 ms 9352 KiB
random_19.txt AC 6 ms 15488 KiB
random_20.txt AC 8 ms 16248 KiB
random_21.txt AC 12 ms 16200 KiB
random_22.txt AC 4 ms 9440 KiB
random_23.txt AC 8 ms 11464 KiB
random_24.txt AC 9 ms 15408 KiB
random_25.txt AC 1 ms 3484 KiB
random_26.txt AC 1 ms 3472 KiB
random_27.txt AC 2 ms 3744 KiB
random_28.txt AC 1 ms 3556 KiB
random_29.txt AC 1 ms 3468 KiB
random_30.txt AC 1 ms 3416 KiB
random_31.txt AC 31 ms 38424 KiB
random_32.txt AC 22 ms 38556 KiB
random_33.txt AC 32 ms 38416 KiB
random_34.txt AC 29 ms 38424 KiB
random_35.txt AC 29 ms 38376 KiB
random_36.txt AC 30 ms 38484 KiB
random_37.txt AC 29 ms 38400 KiB
sample_01.txt AC 1 ms 3396 KiB
sample_02.txt AC 1 ms 3480 KiB
sample_03.txt AC 1 ms 3436 KiB