Submission #66740590


Source Code Expand

#if __has_include("pch.hpp")
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <atcoder/segtree>
#endif
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> order_set;
mt19937_64 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//ld rand(ld a, ld b) {uniform_real_distribution<ld> uni(a, b); return uni(mt_rand);}
//const ld PI=3.141592653589793238462643383279;
const int mxN=1e6+50000;
const int mod=1e9+7;
const int mxlogN=19;
const ll inf=1e18;
const int iinf=1e9;
const int K=60;
int dp[3002][3002];
int a[mxN], b[mxN];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, h, m; cin >> n >> h >> m;
    for(int i=0; i<n; i++) cin >> a[i] >> b[i];
    for(int i=0; i<=n; i++) for(int j=0; j<=h; j++) dp[i][j]=m+1;
    dp[0][0]=0;
    int ans=0;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<=h; j++)
        {
            if(dp[i][j]>m) continue;
            int k=dp[i][j];
            if(j+a[i]<=h) dp[i+1][j+a[i]]=min(dp[i+1][j+a[i]],k);
            if(k+b[i]<=m) dp[i+1][j]=min(dp[i+1][j],k+b[i]);
        }
        int ok=0;
        for(int j=0; j<=h; j++)
        {
            if(dp[i+1][j]<=m) ok=1;
        }
        if(ok) ans=i+1;
        else break;
    }
    cout << ans << "\n";
}





Submission Info

Submission Time
Task E - Battles in a Row
User toniskrijelj
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1600 Byte
Status AC
Exec Time 31 ms
Memory 38844 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 13 ms 32604 KiB
random_02.txt AC 17 ms 35112 KiB
random_03.txt AC 14 ms 22196 KiB
random_04.txt AC 5 ms 12788 KiB
random_05.txt AC 11 ms 22316 KiB
random_06.txt AC 7 ms 11744 KiB
random_07.txt AC 14 ms 29540 KiB
random_08.txt AC 16 ms 30212 KiB
random_09.txt AC 17 ms 25708 KiB
random_10.txt AC 8 ms 20296 KiB
random_11.txt AC 14 ms 28920 KiB
random_12.txt AC 14 ms 20612 KiB
random_13.txt AC 3 ms 6632 KiB
random_14.txt AC 8 ms 13900 KiB
random_15.txt AC 20 ms 36476 KiB
random_16.txt AC 9 ms 22836 KiB
random_17.txt AC 7 ms 10784 KiB
random_18.txt AC 6 ms 9952 KiB
random_19.txt AC 10 ms 25820 KiB
random_20.txt AC 12 ms 28308 KiB
random_21.txt AC 15 ms 23520 KiB
random_22.txt AC 8 ms 20740 KiB
random_23.txt AC 10 ms 15256 KiB
random_24.txt AC 14 ms 27328 KiB
random_25.txt AC 1 ms 3944 KiB
random_26.txt AC 1 ms 3948 KiB
random_27.txt AC 2 ms 5036 KiB
random_28.txt AC 1 ms 3492 KiB
random_29.txt AC 1 ms 3560 KiB
random_30.txt AC 1 ms 3672 KiB
random_31.txt AC 27 ms 38788 KiB
random_32.txt AC 27 ms 38844 KiB
random_33.txt AC 31 ms 38844 KiB
random_34.txt AC 30 ms 38768 KiB
random_35.txt AC 30 ms 38584 KiB
random_36.txt AC 30 ms 38772 KiB
random_37.txt AC 30 ms 38708 KiB
sample_01.txt AC 1 ms 3516 KiB
sample_02.txt AC 1 ms 3548 KiB
sample_03.txt AC 1 ms 3536 KiB