Pagini recente » Cod sursa (job #2631723) | Cod sursa (job #1285562) | Cod sursa (job #1503841) | Cod sursa (job #2006908) | Cod sursa (job #3224737)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n,g;
struct obiecte{
int w,p;
};
bool adevar_greutate(obiecte a,obiecte b)
{
if(a.p == b.p)
return a.w>b.w;
else
return a.p>b.p;
}
int main()
{
int i,s=0;
fin>>n>>g;
obiecte obj[n];
for(i=0;i<n;i++)
fin>>obj[i].w>>obj[i].p;
sort(obj,obj+n,adevar_greutate);
i=0;
while(g-obj[i].w>=0)
{
g=g-obj[i].w;
s=s+obj[i].p;
i++;
}
fout<<s;
return 0;
}