제출 #866237

#제출 시각아이디문제언어결과실행 시간메모리
866237maks007Knapsack (NOI18_knapsack)C++14
37 / 100
1052 ms348 KiB
#include "bits/stdc++.h" using namespace std; //#define int long long signed main () { int W, n; cin >> W >> n; vector <int> v, w, k; for(int i = 0; i < n; i ++) { int V, WW; cin >> V >> WW; v.push_back(V); w.push_back(WW); int K; cin >> K; k.push_back(K); } vector <int> dp(W+1, -1e9); dp[0] = 0; for(int i = 0; i < v.size(); i ++) { for(int j = W; j >= 0; j --) { for(int K = 1; K <= k[i]; K ++) { if(j-w[i]*K >= 0) dp[j] = max(dp[j-w[i]*K]+v[i]*K, dp[j]); } } } cout << *max_element(dp.begin(), dp.end()); return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i = 0; i < v.size(); i ++) {
      |                 ~~^~~~~~~~~~
#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...