Cod sursa(job #1223851)

Utilizator catalincraciunCraciun Catalin catalincraciun Data 29 august 2014 00:06:44
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
// Craciun Catalin
//  Energii
//   Infoarena
#include <iostream>
#include <cstring>
#include <fstream>

struct obj {
	
	int val, weight;
};

using namespace std;

ifstream f("energii.in");
ofstream g("energii.out");

#define GMax 10005

int V[GMax];
int n,weight;

int main() {
	
	f>>n>>weight;
	memset(V, 0, sizeof(V));
	
	for (int i=1;i<=n;i++) {
		int oVal, oWeight;
		f>>oWeight>>oVal;
		for (int j=weight; j>=oWeight;j--)
			if (V[j-oWeight] + oVal > V[j])
				V[j] = V[j-oWeight] + oVal;
	}
	
	g<<V[weight]<<'\n';
	
	f.close();
	g.close();
	
	return 0;
}