19B - Checkout Assistant - CodeForces Solution


dp *1900

Please click on ads to support us..

C++ Code:

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

// Shorthands
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define endl "\n"

#define int long long
#define ll long long
#define ld long double
#define vll vector<ll>
#define vvll vector<vll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll, ll>
#define vpll vector<pll>
#define ff first
#define ss second
#define fill(a, b) memset(a, b, sizeof(a))
#define tll tuple<ll, ll, ll>
#define vtll vector<tll>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define vect(a, n) \
    vll a(n);      \
    rep(i, 0, n) cin >> a[i];
#define all(a) a.begin(), a.end()
#define sortall(a) sort(a.begin(), a.end());
#define PI acos(-1)
#define print cout <<
const int mod = 1000000007;
int helper(int i,int j,vector<vector<int>> &v,vector<vector<int>> &dp){
    if(j>=4000)return 0;
    if(i>=v.size()){
        if(j>=2000)return 0;
        return 1e18;
    }
    if(dp[i][j]!=-1)return dp[i][j];
    int sel=0;int notsel=0;
    sel=v[i][1]+helper(i+1,j+v[i][0],v,dp);
    notsel=helper(i+1,j-1,v,dp);
    return dp[i][j]=min(sel,notsel);
}
void solve()
{
    int a;cin>>a;
    vector<vector<int>> v;
    for(int i=0;i<a;i++){
        int p,q;cin>>p>>q;
        v.pb({p,q});
    }
    vector<vector<int>> dp(2001,vector<int> (4002,-1)); 
    int ans=helper(0,2000,v,dp);
    cout<<ans<<endl;
}
signed main()
{

    int t;
    t = 1;
    // cin >> t;
    
    while (t--)
    {
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments