Cod sursa(job #1643042)
Utilizator | Data | 9 martie 2016 17:19:01 | |
---|---|---|---|
Problema | Energii | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.48 kb |
#include <fstream>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int g,w,eg[1002],cg[1002],a[1002],b[1002];
int main()
{
int i,j;
fin>>g>>w;
for(i=1; i<=g; i++) fin>>eg[i]>>cg[i];
fin.close();
for(i=1; i<=g; i++)
{ for(j=1; j<=w; j++)
if(w>eg[i]) a[j]=b[j];
else a[j]=max(b[j],b[j-eg[i]]+cg[i]);
for(j=1; j<=g; j++)
b[j]=a[j];
}
fout<<a[g];
return 0;
}