This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/***AUTHOR: ChasingClouds***/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int S, N;
cin >> S >> N;
vector<int> value(N);
vector<int> weight(N);
vector<int> copies(N);
for(int i=0; i<N; i++) {
cin >> value[i] >> weight[i] >> copies[i];
}
vector<int> VW(N);
for(int i=0; i<N; i++) VW[i] = value[i]/weight[i];
vector<int> pos(N);
iota(pos.begin(), pos.end(), 0);
//sort(VW.begin(), VW.end(), greater<int> ());
sort(pos.begin(), pos.end(), [&](int i, int j){return VW[i] < VW[j];});
reverse(pos.begin(), pos.end());
int ans = 0;
for(int i=0; i<N; i++) {
while(copies[pos[i]]--) {
if(S - weight[pos[i]] >= 0){
ans += value[pos[i]];
S = S - weight[pos[i]];
}
}
}
cout << ans;
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... |