This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Cake {
int value;
int weight;
int quantity;
};
bool cmp(const Cake& a, const Cake& b) {
return (double)a.value / a.weight > (double)b.value / b.weight;
}
int main() {
int S, N;
cin >> S >> N;
vector<Cake> cakes(N);
for (int i = 0; i < N; i++) {
cin >> cakes[i].value >> cakes[i].weight >> cakes[i].quantity;
}
sort(cakes.begin(), cakes.end(), cmp);
int maxValue = 0;
int remainingWeight = S;
for (const Cake& cake : cakes) {
int maxQuantity = min(cake.quantity, remainingWeight / cake.weight);
maxValue += maxQuantity * cake.value;
remainingWeight -= maxQuantity * cake.weight;
}
cout << maxValue << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |