Pagini recente » Cod sursa (job #262049) | Cod sursa (job #735855) | Cod sursa (job #1758152) | Cod sursa (job #1876374) | Cod sursa (job #1009400)
#include <fstream>
#define NMax 1005
#define GMax 5005
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int G, W, E[NMax], C[NMax], DP[2][GMax], l=1;
void Read()
{
fin>>G>>W;
for(int i=1;i<=G;i++)
{
fin>>E[i]>>C[i];
}
}
void Solve()
{
for(int i=1;i<=G; i++,l=1-l)
for(int j=1; j<=W; j++)
{
DP[l][j]=DP[1-l][j];
if(j>=E[i])
DP[l][j]=max(DP[l][j],DP[1-l][j-E[i]]+C[i]);
}
}
void Print()
{
fout<<DP[1-l][W]<<'\n';
}
int main()
{
Read();
Solve();
Print();
return 0;
}