제출 #505109

#제출 시각아이디문제언어결과실행 시간메모리
505109hkimKnapsack (NOI18_knapsack)C++14
100 / 100
123 ms4828 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int S, N; int V[100005], W[100005], K[100005]; vector<pair<int, int>> weights[2005]; int dp[2005]; int main() { cin >> S >> N; for (int i = 0; i < N; i++) { cin >> V[i] >> W[i] >> K[i]; weights[W[i]].emplace_back(make_pair(V[i], K[i])); } for (int i = 0; i <= S; i++) { if (weights[i].empty()) continue; sort(weights[i].begin(), weights[i].end(), greater<>()); int weight_idx = 0; for (int j = 0; j * i < S; j++) { if (weight_idx >= weights[i].size()) break; for (int k = S; k >= i; k--) { dp[k] = max(dp[k], dp[k - i] + weights[i][weight_idx].first); } weights[i][weight_idx].second--; if (weights[i][weight_idx].second == 0) weight_idx++; } } cout << dp[S] << endl; for (int i = 0; i <= S; i++) { //cout << dp[i] << " "; } //cout << endl; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:24:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |             if (weight_idx >= weights[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...