Pagini recente » Diferente pentru problema/text3 intre reviziile 6 si 2 | Cod sursa (job #933484) | Monitorul de evaluare | Cod sursa (job #2183221) | Cod sursa (job #902736)
Cod sursa(job #902736)
#include <fstream>
#include <iostream>
using namespace std;
fstream f("rucsac.in" , ios::in), fo("rucsac.out", ios::out);
int mat[10001];
int main()
{
int n,g,v,w,s=0;
f>>n>>g;
for(int i=1;i<=n;i++)
{
f>>w>>v;
for(int j=g-w;j>=0;j--)
if(mat[j]+v>mat[j+w])
{
mat[j+w]=mat[j]+v;
if ( mat[j+w]>s)
s=mat[j+w];
}
}
fo<<s;
return 0;
}