Pagini recente » Cod sursa (job #1925788) | Cod sursa (job #1411999) | Cod sursa (job #3214209) | Cod sursa (job #550383) | Cod sursa (job #2691455)
#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 < g && it >= 1){
sum += v[it].profit;
gr += v[it--].greutate;
}
out<<sum;
}