Cod sursa(job #2272632)
Utilizator | Data | 30 octombrie 2018 15:08:06 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
#define cin fin
#define cout fout
int n,gmax,g,p;
int profit[10001];
int main()
{
cin>>n>>gmax;
for(int i=1; i<=n; i++)
{
cin>>g>>p;
for(int j=gmax-g; j>=0; j--)
{
int prof=profit[j]+p;
if(prof>profit[j+g])
profit[j+g]=prof;
}
}
cout<<profit[gmax];
return 0;
}