제출 #541267

#제출 시각아이디문제언어결과실행 시간메모리
541267gromperenKnapsack (NOI18_knapsack)C++14
100 / 100
57 ms5008 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ios::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; vector<vector<pair<int,int>>> obj(s+1); vector<int> v(n), w(n), k(n); for (int i = 0; i < n; ++i) { cin >> v[i] >> w[i] >> k[i]; obj[w[i]].push_back({v[i], k[i]}); } vector<ll> dp(s+1); for (int i =0; i <=s; ++i) { if (!obj[i].size()) continue; sort(obj[i].begin(), obj[i].end(), greater<pair<int,int>>()); int cur_used = 0; for (int j = 0; j * i <= s && cur_used < obj[i].size(); ++j) { for (int r = s; r >= i; --r) { dp[r] = max(dp[r], dp[r-i] + obj[i][cur_used].first); } obj[i][cur_used].second--; if (obj[i][cur_used].second == 0) cur_used++; } } cout << dp[s] << "\n"; /* for (int i = 0; i< n; ++i) { for (int j = s; j >= w[i]; --j) { for (int t = 0; t <= k[i]; ++t) { if (j >= w[i] * t) { dp[j] = max(dp[j], dp[j - w[i] * t] + v[i] * t); } } } } cout << dp[s] << "\n"; */ return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:27:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int j = 0; j * i <= s && cur_used < obj[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...