Cod sursa(job #948903)

Utilizator A63N7pTudor Nazarie A63N7p Data 11 mai 2013 21:38:39
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#ifndef __cplusplus
	#error A C++ compiler is required to compile
#endif
#ifndef __FSTREAM_H
	#include<fstream>
	#define __FSTREAM_H
#endif
#ifndef __STRING_H
	#include<cstring>
	#define __STRING_H
#endif
using namespace std;

ifstream in;
ofstream out;

int d1[10001],d2[10002]

int main()
{
	in.open("energii.in");
	out.open("energii.out");
	int n,G;
	in>>n>>G;
	int w,p;
	for(int i=1;i<=n;i++)
	{
		in>>w>>p;
		for(int j=1;j<=G;j++)
		{
			if(j<w)
				d2[j]=d1[j];
			else if(d1[j]<d1[j-w]+p)
				d2[j]=d1[j-w]+p;
			else
				d2[j]=d1[j];
		}
		memcpy(d1,d2,sizeof(d2));
	}
	out<<d1[G]<<"\n";	
	in.close();
	out.close();
	return 0;
}