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 <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ff first
#define ss second
#define pii pair<int, int>
struct stdfloat {
int v, w, k;
};
bool cmp(stdfloat a, stdfloat b) {
if (a.v * b.w != b.v * a.w) return a.v * b.w > b.v * a.w;
return a.w < b.w;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int s, n;
cin >> s >> n;
vector<stdfloat> a(n);
for (auto &i : a)
cin >> i.v >> i.w >> i.k;
sort(a.begin(), a.end(), cmp);
ll ans = 0;
for (auto i : a) {
ans += (ll)min(s / i.w, i.k) * i.v;
s -= min(s / i.w, i.k) * i.w;
}
cout << ans;
}
# | 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... |