Submission #66761267


Source Code Expand

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <time.h>
#include <sstream>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <assert.h>
#include <iomanip>
#include <bitset>
#include <functional>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ull unsigned long long
#define int long long
#define F first
#define S second
#define nl "\n"
#define sortv(v) sort(v.begin(),v.end())
#define rsortv(v) sort(v.rbegin(),v.rend())
#define all(v) v.begin(),v.end()
#define div 1000000007
#define div2 998244353
#define PI 3.141592653589793
#define inf 1000000000000000000LL
#define blk 320
#define pb push_back


void solve()
{
    int n,h,m;cin>>n>>h>>m;
    int a[n + 1], b[n + 1];
    for (int i = 1; i <= n; i++)
        cin>>a[i]>>b[i];
    
    int dp[n + 1][h + 1];
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= h; j++)
        {
            if (i == 0)
                dp[i][j] = m;
            else
               dp[i][j] = -1;
        }
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= h; j++)
        {
            if (j - a[i] >= 0)
                dp[i][j] = dp[i - 1][j - a[i]];
            
            if (dp[i - 1][j] - b[i] >= 0)
                dp[i][j] = max(dp[i][j], dp[i - 1][j] - b[i]);
        }
    }

    int ans = 0;
    for (int i = n; i > 0; i--)
    {
        if (dp[i][h] >= 0)
        {
            ans = i;
            break;
        }
    }
    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}

Submission Info

Submission Time
Task E - Battles in a Row
User prashant933
Language C++ 20 (gcc 12.2)
Score 450
Code Size 2078 Byte
Status AC
Exec Time 54 ms
Memory 73916 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 25 ms 41468 KiB
random_02.txt AC 29 ms 47368 KiB
random_03.txt AC 18 ms 28696 KiB
random_04.txt AC 10 ms 17332 KiB
random_05.txt AC 16 ms 24540 KiB
random_06.txt AC 8 ms 13796 KiB
random_07.txt AC 29 ms 43648 KiB
random_08.txt AC 35 ms 52400 KiB
random_09.txt AC 23 ms 32632 KiB
random_10.txt AC 17 ms 26096 KiB
random_11.txt AC 30 ms 45536 KiB
random_12.txt AC 20 ms 30028 KiB
random_13.txt AC 4 ms 7696 KiB
random_14.txt AC 11 ms 17052 KiB
random_15.txt AC 39 ms 57196 KiB
random_16.txt AC 16 ms 22844 KiB
random_17.txt AC 12 ms 17408 KiB
random_18.txt AC 10 ms 15884 KiB
random_19.txt AC 18 ms 28304 KiB
random_20.txt AC 18 ms 29540 KiB
random_21.txt AC 19 ms 29904 KiB
random_22.txt AC 9 ms 15636 KiB
random_23.txt AC 14 ms 20224 KiB
random_24.txt AC 19 ms 28028 KiB
random_25.txt AC 1 ms 3656 KiB
random_26.txt AC 2 ms 3596 KiB
random_27.txt AC 2 ms 4916 KiB
random_28.txt AC 1 ms 3632 KiB
random_29.txt AC 1 ms 3504 KiB
random_30.txt AC 1 ms 3660 KiB
random_31.txt AC 52 ms 73912 KiB
random_32.txt AC 52 ms 73916 KiB
random_33.txt AC 52 ms 73916 KiB
random_34.txt AC 51 ms 73812 KiB
random_35.txt AC 54 ms 73916 KiB
random_36.txt AC 54 ms 73852 KiB
random_37.txt AC 53 ms 73848 KiB
sample_01.txt AC 1 ms 3404 KiB
sample_02.txt AC 1 ms 3616 KiB
sample_03.txt AC 1 ms 3508 KiB