Pagini recente » Cod sursa (job #1035927) | Cod sursa (job #217065) | Cod sursa (job #2109433) | Cod sursa (job #2643570) | Cod sursa (job #3247155)
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
pair<pair<double, int>, int> obiecte[1000];
int n, gm;
double V;
int main() {
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
fin >> n >> gm;
for(int i = 0; i < n; i++) {
fin >> obiecte[i].first.second >> obiecte[i].second;
obiecte[i].first.first = 1.00 * obiecte[i].second / obiecte[i].first.second;
}
sort(obiecte, obiecte + n);
for(int i = n - 1; i >= 0; i--) {
if(gm - obiecte[i].first.second < 0) {
V += (double)gm / obiecte[i].first.second * obiecte[i].second;
break;
} else {
V += obiecte[i].second;
gm -= obiecte[i].first.second;
}
}
fout << V;
}