Submission #68230766


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#include <iostream>
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {return os<<'(' <<p.first<<", "<<p.second<<')';}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {os<<'[';for(auto it=v.begin();it!=v.end();++it){os<<*it; if(next(it)!=v.end()){os<<", ";}}return os<<']';}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {os<<"[\n";for(auto it=vv.begin();it!=vv.end();++it){os<<"  "<<*it;if(next(it)!=vv.end()){os<<",\n";}else{os<<"\n";}}return os<<"]";}
#define dump(x) cerr << #x << " = " << (x) << '\n'
#else
#define dump(x) (void)0
#endif
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
template<class T> using pq = priority_queue<T>;
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>;
#define out(x) cout<<x<<'\n'
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define OVERLOAD_REP(_1,_2,_3,name,...) name
#define REP1(i,n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
template<class T> inline bool chmin(T& a, T b) {if(a > b){a = b; return true;} else {return false;}};
template<class T> inline bool chmax(T& a, T b) {if(a < b){a = b; return true;} else {return false;}};
const ll INF=(1LL<<60);
const ll mod=998244353;
using Graph = vector<vector<ll>>;
using Network = vector<vector<pair<ll,ll>>>;
using Grid = vector<string>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {1, 1,  1, 0,  0, -1, -1, -1};
const int dy2[8] = {1, 0, -1, 1, -1,  1,  0, -1};

void solve() {
    ll N, H, M;
    cin >> N >> H >> M;
    vector<ll> A(N), B(N);
    rep(i, N)  cin >> A[i] >> B[i];
    vector dp(N + 1, vector<ll>(H + 1, -INF));
    dp[0][H] = M;
    rep(i, N) {
        rep(h, H+1) {
            if (dp[i][h] == -1) continue;
            if (h >= A[i]) {
                chmax(dp[i + 1][h - A[i]], dp[i][h]);
            }
            if (dp[i][h] >= B[i]) {
                chmax(dp[i + 1][h], dp[i][h] - B[i]);
            }
        }
    }
    ll ans = 0;
    rep(i, 1, N+1) {
        bool ok = false;
        rep(h, H + 1) {
            if (dp[i][h] >= 0) {
                ok = true;
                break;
            }
        }
        if (ok) {
            ans = i;
        } else {
            break;
        }
    }
    out(ans);
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

Submission Info

Submission Time
Task E - Battles in a Row
User tatesoto
Language C++ 23 (gcc 12.2)
Score 450
Code Size 2908 Byte
Status AC
Exec Time 47 ms
Memory 73712 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 24 ms 41464 KiB
random_02.txt AC 28 ms 47316 KiB
random_03.txt AC 16 ms 28452 KiB
random_04.txt AC 9 ms 17076 KiB
random_05.txt AC 13 ms 24168 KiB
random_06.txt AC 7 ms 13380 KiB
random_07.txt AC 24 ms 43444 KiB
random_08.txt AC 31 ms 52344 KiB
random_09.txt AC 19 ms 32408 KiB
random_10.txt AC 14 ms 25776 KiB
random_11.txt AC 27 ms 45420 KiB
random_12.txt AC 17 ms 29736 KiB
random_13.txt AC 3 ms 7316 KiB
random_14.txt AC 9 ms 16976 KiB
random_15.txt AC 33 ms 56952 KiB
random_16.txt AC 13 ms 22636 KiB
random_17.txt AC 10 ms 17176 KiB
random_18.txt AC 9 ms 15468 KiB
random_19.txt AC 15 ms 27964 KiB
random_20.txt AC 16 ms 29176 KiB
random_21.txt AC 17 ms 29452 KiB
random_22.txt AC 8 ms 15640 KiB
random_23.txt AC 11 ms 19964 KiB
random_24.txt AC 15 ms 27648 KiB
random_25.txt AC 1 ms 3708 KiB
random_26.txt AC 1 ms 3624 KiB
random_27.txt AC 2 ms 4668 KiB
random_28.txt AC 1 ms 3512 KiB
random_29.txt AC 1 ms 3460 KiB
random_30.txt AC 1 ms 3668 KiB
random_31.txt AC 45 ms 73584 KiB
random_32.txt AC 41 ms 73580 KiB
random_33.txt AC 47 ms 73712 KiB
random_34.txt AC 45 ms 73624 KiB
random_35.txt AC 46 ms 73596 KiB
random_36.txt AC 45 ms 73592 KiB
random_37.txt AC 45 ms 73584 KiB
sample_01.txt AC 1 ms 3528 KiB
sample_02.txt AC 1 ms 3668 KiB
sample_03.txt AC 1 ms 3436 KiB