# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
978429 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 0 ms | 348 KiB |
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>
#define ll long long
#define endl '\n'
using namespace std;
int main(){
ll s, n; cin>>s>>n;
ll v[n], w[n], k[n];
vector<pair<ll, ll>> vp;
for(ll i=0;i<n;i++){
cin>>v[i]>>w[i]>>k[i];
vp.push_back(make_pair(v[i], i));
}
sort(vp.begin(), vp.end(), greater<>());
for(auto i: vp) cout<<"e "<<i.first<<" "<<i.second<<endl;
ll we=0, sum=0;
for(ll i=0;i<vp.size();i++){
ll ind = vp[i].second;
while(we+w[ind]<=s && k[ind]!=0){
sum+=v[ind];
we+=w[ind];
k[ind]--;
}
}
cout<<sum<<endl;
return 0;
}
Compilation message (stderr)
# | 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... |