Submission #651534

#TimeUsernameProblemLanguageResultExecution timeMemory
651534ChasingCloudsKnapsack (NOI18_knapsack)C++14
12 / 100
818 ms296 KiB
/***AUTHOR: ChasingClouds***/ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll S, N; cin >> S >> N; vector<ll> value(N); vector<ll> weight(N); vector<ll> copies(N); for(int i=0; i<N; i++) { cin >> value[i] >> weight[i] >> copies[i]; } vector<ll> VW(N); for(int i=0; i<N; i++) VW[i] = value[i]/weight[i]; vector<ll> pos(N); iota(pos.begin(), pos.end(), 0); //sort(VW.begin(), VW.end(), greater<int> ()); sort(pos.begin(), pos.end(), [&](ll i, ll j){return VW[i] < VW[j];}); reverse(pos.begin(), pos.end()); ll ans = 0; for(ll 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...