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 <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... |