Submission #66739708


Source Code Expand

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

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define endl '\n';
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
    cerr << ' ' << H;
    dbg_out(T...);
}
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
typedef long long ll;
const int N = 3e5 + 5;

int dp[3005][3005];
bool vis[3005][3005];
int n, h, m;
int a[N], b[N];

int solve(int i, int j) {
    if (j > h) return 1e9;
    if (i == 0) {
        if (j == h) {
            return 0;
        }
        return 1e9;
    }
    int& rs = dp[i][j];
    if (vis[i][j]) return rs;
    vis[i][j] = 1;
    rs = min(b[i - 1] + solve(i - 1, j), solve(i - 1, j + a[i - 1]));
    return rs;
}

void test_case() {
    memset(dp, -1, sizeof(dp));
    cin >> n >> h >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int ans = 0;
    for (int i = n; i >= 1; i--) {
        for (int j = 0; j <= h; j++) {
            if (solve(i, j) <= m) {
                ans = i;
                break;
            }
        }
        if (ans) {
            break;
        }
    }
    cout << ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    // cin >> T;
    while (T--) {
        test_case();
    }
    return 0;
}

Submission Info

Submission Time
Task E - Battles in a Row
User MSteine
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1656 Byte
Status AC
Exec Time 199 ms
Memory 47916 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 128 ms 46356 KiB
random_02.txt AC 139 ms 46960 KiB
random_03.txt AC 75 ms 43608 KiB
random_04.txt AC 49 ms 41112 KiB
random_05.txt AC 77 ms 44960 KiB
random_06.txt AC 30 ms 41116 KiB
random_07.txt AC 132 ms 45308 KiB
random_08.txt AC 150 ms 45580 KiB
random_09.txt AC 75 ms 44448 KiB
random_10.txt AC 75 ms 43052 KiB
random_11.txt AC 132 ms 45300 KiB
random_12.txt AC 60 ms 43036 KiB
random_13.txt AC 24 ms 39536 KiB
random_14.txt AC 38 ms 41432 KiB
random_15.txt AC 160 ms 47088 KiB
random_16.txt AC 76 ms 45932 KiB
random_17.txt AC 36 ms 40648 KiB
random_18.txt AC 35 ms 40376 KiB
random_19.txt AC 92 ms 46104 KiB
random_20.txt AC 96 ms 47692 KiB
random_21.txt AC 66 ms 43848 KiB
random_22.txt AC 58 ms 47264 KiB
random_23.txt AC 41 ms 41796 KiB
random_24.txt AC 88 ms 47496 KiB
random_25.txt AC 16 ms 39084 KiB
random_26.txt AC 16 ms 39096 KiB
random_27.txt AC 17 ms 39320 KiB
random_28.txt AC 16 ms 38784 KiB
random_29.txt AC 16 ms 38788 KiB
random_30.txt AC 17 ms 38700 KiB
random_31.txt AC 107 ms 47732 KiB
random_32.txt AC 21 ms 47764 KiB
random_33.txt AC 107 ms 47916 KiB
random_34.txt AC 196 ms 47804 KiB
random_35.txt AC 198 ms 47800 KiB
random_36.txt AC 199 ms 47772 KiB
random_37.txt AC 196 ms 47876 KiB
sample_01.txt AC 16 ms 38768 KiB
sample_02.txt AC 16 ms 38800 KiB
sample_03.txt AC 16 ms 38812 KiB