Submission #209526

#TimeUsernameProblemLanguageResultExecution timeMemory
209526model_codeKnapsack (NOI18_knapsack)C++14
100 / 100
188 ms1660 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int S, N, V, W, K; vector <pair<int, int>> A[2001]; long long dp[2001], answer; int main(){ cin >> S >> N; for(int i = 0; i < N; i++){ cin >> V >> W >> K; A[W].push_back(make_pair(V, K)); } for(int i = 1; i <= S; i++){ sort(A[i].begin(), A[i].end(), greater<pair<int, int>>()); int index = 0; for(int j = 0; j < S / i; j++){ if(index >= A[i].size()) break; for(int k = S; k >= i; k--){ dp[k] = max(dp[k], dp[k - i] + A[i][index].first); answer = max(answer, dp[k]); } A[i][index].second--; if(A[i][index].second == 0) index++; } } cout << answer << endl; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:18:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(index >= A[i].size()) break;
       ~~~~~~^~~~~~~~~~~~~~
#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...