Pagini recente » Cod sursa (job #2534836) | Cod sursa (job #1909255) | Cod sursa (job #2730968) | Cod sursa (job #2682049) | Cod sursa (job #2529328)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
struct ghiozdane{
int pf,gr;
}v[100001];
int n,g,sumgr = 0,prf = 0;
ghiozdane ghiozdan[10000];
int main()
{
fin >> n >> g;
for(int i = 1;i<=n;i++){
fin >> ghiozdan[i].gr >> ghiozdan[i].pf;
}
for(int i = 1;i<=n-1;i++){
for(int j = i+1;j<=n;j++){
if(ghiozdan[j].pf > ghiozdan[i].pf){
swap(ghiozdan[j],ghiozdan[i]);
}
}
}
for(int i = 1;i<=n;i++){
if(sumgr+ghiozdan[i].gr <= g){
sumgr+=ghiozdan[i].gr;
prf+=ghiozdan[i].pf;
}
}
fout << prf;
return 0;
}