제출 #651533

#제출 시각아이디문제언어결과실행 시간메모리
651533ChasingCloudsKnapsack (NOI18_knapsack)C++14
12 / 100
919 ms320 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); 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 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...