Cod sursa(job #2568783)

Utilizator TheGodFather2131Alexandru Miclea TheGodFather2131 Data 4 martie 2020 09:50:14
Problema Problema rucsacului Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <bits/stdc++.h>

using namespace std;

//#include <iostream>
#include <fstream>
ifstream fin("rucsac.in"); ofstream fout("rucsac.out");

//VARIABLES

int n;
int G;
int dp[10005];
int g[5005];
int p[5005];

//FUNCTIONS



//MAIN
int main() {

    fin >> n >> G;
    for (int i = 1; i <= n; i++){
        fin >> g[i] >> p[i];
    }

    for (int i = 1; i <= n; i++){
        for (int j = G - g[i]; j >= 0; j--){
            dp[j + g[i]] = max(dp[j] + p[i], dp[j + g[i]]);
        }
    }

    fout << dp[G];

    return 0;
}