이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <queue>
using namespace std;
struct item{
int p, w, n;
float r;
bool operator<(const item& o) const
{
return r <= o.r;
}
};
int main() {
int s, n;
cin >> s >> n;
priority_queue<item> items;
for (int i=0;i<n;i++){
item j;
cin >> j.p >> j.w >> j.n;
j.r = (float)j.p/(float)j.w;
items.push(j);
}
int totalProfit = 0;
int remainingWeight = s;
while (items.size() != 0){
item i = items.top();
items.pop();
if (i.w > remainingWeight) continue;
int maxNum = ((int)remainingWeight/(int)i.w) > i.n ? i.n : ((int)remainingWeight/(int)i.w);
totalProfit += maxNum * i.p;
remainingWeight = remainingWeight-(i.w*maxNum);
}
cout << totalProfit << endl;
}
# | 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... |