Pagini recente » Cod sursa (job #899777) | Cod sursa (job #1167750) | Cod sursa (job #2980258) | Cod sursa (job #2226900) | Cod sursa (job #2691457)
#include <bits/stdc++.h>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
struct ex{
int profit, greutate;
}v[5005];
int n, g, sum, gr;
struct cmp{
bool operator()(ex a, ex b){
return a.profit < b.profit;
}
};
int main(){
in>>n>>g;
for(int i = 1; i <= n; i++)
in>>v[i].greutate>>v[i].profit;
sort(v + 1, v + n + 1, cmp());
int it = n;
while(gr + v[it].greutate <= g && it >= 1){
sum += v[it].profit;
gr += v[it--].greutate;
}
out<<sum;
}