Cod sursa(job #1489908)
Utilizator | Data | 22 septembrie 2015 11:41:52 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include<fstream>
using namespace std;
int a[50005];
bool efolosit[50005];
int main(){
efolosit[0] = true;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n, greutate, i, j;
f >> n >> greutate;
for(int q = 1; q <= n; q++){
f >> i >> j;
for(int k = greutate; k >= 0; k--){
if(efolosit[k] && a[k + i] < a[k] + j){
a[k + i] = a[k] + j;
efolosit[k + i] = true;
}
}
}
a[0] = 0;
for (int i = 0; i <= greutate; i++){
if (a[i] > a[0])
a[0] = a[i];
}
g << a[0];
}