Cod sursa(job #2543026)

Utilizator FasoleboiTudor Gadalean Fasoleboi Data 10 februarie 2020 19:44:19
Problema Problema rucsacului Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <bits/stdc++.h>
#define N 5001
using namespace std;

ifstream fin("rucsac.in");
ofstream fout("rucsac.out");

int n, g, w[N], p[N], rez[10001], solv = 0;

int main(){
    fin>>n>>g;
    for(int i=1;i<=n;i++){
        fin>>w[i]>>p[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=g-w[i];j>=0;j--){
            if(rez[j+w[i]]<rez[j] + p[i]){
                rez[j+w[i]] = rez[j] + p[i];
            }
        }
    }
    fout<<rez[g];
    return 0;
}