Cod sursa(job #2835574)

Utilizator PatrickvasileSoltan Cristian Patrickvasile Data 18 ianuarie 2022 21:50:46
Problema Problema rucsacului Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.6 kb
#include <bits/stdc++.h>
#define fri(a, b) for (int i = (a); i < (b); ++i)
#define frj(a, b) for(int j = a; j < b; j++)
#define frk(a, b) for(int k = a; k < b; k++)
#define frm(a, b, i) for(int i = b; i >= a; i--)
#define ll long long
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define sz size()
#define rall(x) x.rbegin(), x.rend()
#define ct(x) cout << x
#define cts(x) cout << x << ' '
#define ctn(x) cout << x << '\n'
using namespace std;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using ml = map<ll, ll>;
template <typename T>void read(T n, vector<T> &a){fri(0, n){cin >> a[i];}}
template<typename T> void print(T n, vector<T> &a){fri(0, n){cts(a[i]);}}
 
const int mx = 1000001;

string __fname = "ruxac"; ifstream in (__fname + ".in"); ofstream out (__fname + ".out"); 
#define cin in 
#define cout out
int n, m;
int a[5001];
int b[5001];

void solve(){
    cin >> n >> m;
    fri(0, n){
        cin >> a[i] >> b[i];
    }
    vi d(m  +1);
    vi p(m  +1);
    fri(0, m + 1){
        if(i < a[0]){
            d[i] = 0;
        }
        else{
            d[i] = b[0];
        }
    }
    bool van = false;
    fri(1, n){
        if(van) d = p;
        p.clear();
        frj(0, m + 1){
            van = true;
            if(j < a[i]){
                p.pb(d[j]);
            }
            else{
                p.pb(max(d[j], b[i] + d[j - a[i]]));
            }
        }
    }
    ctn(p[m]);
}
 

int main()
{   
    ios_base::sync_with_stdio(0); cin.tie(0);
    // int t;
    // cin >> t;
    // while(t--)
        solve();
}