Pagini recente » Cod sursa (job #2290386) | Cod sursa (job #141467) | Cod sursa (job #2492944) | Cod sursa (job #301306) | Cod sursa (job #3224738)
#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.w == b.w)
return a.p>b.p;
else
return a.w>b.w;
}
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;
}