Pagini recente » Cod sursa (job #309156) | Statistici Andrei Mihu (cashinmypocket) | Cod sursa (job #2646613) | Cod sursa (job #699195) | Cod sursa (job #1600709)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <vector>
using namespace std;
struct obiect{
double g, v, vu;
}x;
int N, Gmax, G, V, a, b;
vector<obiect>v;
bool comp(obiect x, obiect y){
return x.vu>y.vu;
}
int main()
{
freopen("rucsac.in", "rt", stdin);
freopen("rucsac.out", "wt", stdout);
scanf("%d%d", &N, &Gmax);
v.assign(N+1, x);
for(int i=1; i<=N; i++){
scanf("%d%d", &a, &b);
v[i].g = a;
v[i].v = b;
v[i].vu = v[i].v / v[i].g;
}
sort(v.begin()+1, v.end(), comp);
int o=1;
while(G + v[o].g <= Gmax && o<=N){
G += v[o].g;
V += v[o++].v;
}
cout<<V<<'\n';
}