제출 #907679

#제출 시각아이디문제언어결과실행 시간메모리
907679Ca7Ac1Knapsack (NOI18_knapsack)C++17
100 / 100
123 ms2640 KiB
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <string> #include <map> #include <set> #include <math.h> #define ll int #define pll pair<ll, ll> using namespace std; int main() { ll s; ll n; cin >> s >> n; vector<priority_queue<ll, vector<ll>, greater<ll>>> arr(s, priority_queue<ll, vector<ll>, greater<ll>>()); for (ll i = 0; i < n; i++) { ll v; ll w; ll k; cin >> v >> w >> k; while (arr[w - 1].size() * w <= s && k > 0) { arr[w - 1].push(v); k--; } while (arr[w - 1].top() < v && k > 0) { arr[w - 1].pop(); arr[w - 1].push(v); k--; } } vector<ll> dp(s + 1, 0); for (ll i = 1; i <= s; i++) { auto &values = arr[i - 1]; while (!values.empty()) { ll curr = values.top(); values.pop(); for (ll j = s; j >= 0; j--) { if (j + i <= s) { dp[j + i] = max(dp[j + i], dp[j] + curr); } } } } ll sol = 0; for (ll i : dp) { sol = max(sol, i); } cout << sol << '\n'; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:29:38: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |         while (arr[w - 1].size() * w <= s && k > 0)
      |                ~~~~~~~~~~~~~~~~~~~~~~^~~~
#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...