Pagini recente » Cod sursa (job #1194916) | Cod sursa (job #2534101) | Cod sursa (job #2548734) | Cod sursa (job #3221900) | Cod sursa (job #2529472)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
struct ghiozdane{
int pf,gr;
}v[10000];
int N,G,sumgr = 0,prf = 0;
ghiozdane ghiozdan[10000];
int main()
{
fin >> N >> G;
if(N<=5000 && G <=10000 && G>=1 && N>=1){
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].gr < ghiozdan[i].gr){
swap(ghiozdan[j],ghiozdan[i]);
}
if(ghiozdan[i].gr == ghiozdan[j].gr && ghiozdan[i].pf < ghiozdan[j].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;
}