Cod sursa(job #3342954)

Utilizator Mateixx1Trandafir Matei Mateixx1 Data 26 februarie 2026 10:39:25
Problema Problema rucsacului Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.36 kb
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n,gre,x,val,dp[10010];

int main() {
    f>>n>>gre;
    for(int i=1; i<=n; i++) {
        f>>x>>val;
        for(int j=gre; j>=x; j--) {
            dp[j]=max(dp[j],dp[j-x]+val);
        }
    }
    g<<dp[gre];
    f.close();
    g.close();
    return 0;
}