이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |