제출 #438691

#제출 시각아이디문제언어결과실행 시간메모리
438691HaidaraKnapsack (NOI18_knapsack)C++17
100 / 100
160 ms3812 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; // i is the wieght for(int j=0;j<S/i&&index<A[i].size();j++) { // j is capacity of knapsack from i wieght 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; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:21:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for(int j=0;j<S/i&&index<A[i].size();j++)
      |                      ~~~~~^~~~~~~~~~~~
#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...