Submission #68242110


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<bitset<3001>> dp(H + 1, bitset<3001>(0));
    dp[H][M] = 1;
    rep(i, N) {
        vector<bitset<3001>> next_dp(H + 1, bitset<3001>(0));
        bool possible = false;
        rep(h, H + 1) {
            if (h >= A[i]) {
                next_dp[h - A[i]] |= dp[h];
            }
            next_dp[h] |= (dp[h] >> B[i]);
        }
        dp = next_dp;
        rep(h, H + 1) {
            if (dp[h].any()) {
                possible = true;
                break;
            }
        }
        if (!possible) {
            out(i);
            return;
        }
    }
    out(N);
}

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 2837 Byte
Status AC
Exec Time 1112 ms
Memory 5624 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 40 ms 4636 KiB
random_02.txt AC 238 ms 4688 KiB
random_03.txt AC 310 ms 4688 KiB
random_04.txt AC 28 ms 4952 KiB
random_05.txt AC 113 ms 4156 KiB
random_06.txt AC 141 ms 4572 KiB
random_07.txt AC 145 ms 4920 KiB
random_08.txt AC 289 ms 5136 KiB
random_09.txt AC 395 ms 4612 KiB
random_10.txt AC 22 ms 4660 KiB
random_11.txt AC 200 ms 4948 KiB
random_12.txt AC 388 ms 4940 KiB
random_13.txt AC 37 ms 4548 KiB
random_14.txt AC 190 ms 4852 KiB
random_15.txt AC 428 ms 4992 KiB
random_16.txt AC 18 ms 3992 KiB
random_17.txt AC 214 ms 5212 KiB
random_18.txt AC 205 ms 5356 KiB
random_19.txt AC 18 ms 4252 KiB
random_20.txt AC 72 ms 4128 KiB
random_21.txt AC 364 ms 4684 KiB
random_22.txt AC 9 ms 3716 KiB
random_23.txt AC 241 ms 4756 KiB
random_24.txt AC 162 ms 3952 KiB
random_25.txt AC 2 ms 3720 KiB
random_26.txt AC 2 ms 3572 KiB
random_27.txt AC 19 ms 3892 KiB
random_28.txt AC 1 ms 3656 KiB
random_29.txt AC 1 ms 3568 KiB
random_30.txt AC 3 ms 5560 KiB
random_31.txt AC 950 ms 5544 KiB
random_32.txt AC 793 ms 5392 KiB
random_33.txt AC 1112 ms 5400 KiB
random_34.txt AC 963 ms 5568 KiB
random_35.txt AC 952 ms 5508 KiB
random_36.txt AC 965 ms 5624 KiB
random_37.txt AC 950 ms 5452 KiB
sample_01.txt AC 1 ms 3572 KiB
sample_02.txt AC 3 ms 5444 KiB
sample_03.txt AC 1 ms 3500 KiB