제출 #916211

#제출 시각아이디문제언어결과실행 시간메모리
916211lamterKnapsack (NOI18_knapsack)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> const int M = 2000; std::vector <std::pair <int, int>> items[M + 1]; int dp[M + 1]; int main(void) { std::ios_base::sync_with_stdio(0); std::cin.tie(nullptr); int S, n; std::cin >> S >> n; for (int i = 0; i < n; i += 1) { int v, w, k; std::cin >> v >> w >> k; items[w].push_back(v, std::min(k, S / w)); } for (int w = 1; w <= S; w += 1) { std::sort(items[w].begin(), items[w].end(), std::greater <> ()); for (auto [v, cnt] : items[w]) { int total = 0; for (int i = 1; i <= cnt and total <= S; i += 1) { for (int t = S; t >= w; t -= 1) dp[t] = std::max(dp[t], dp[t - w] + v); total += w; } } } std::cout << dp[S] << '\n'; return 0^0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:15:43: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int&, const int&)'
   15 |   items[w].push_back(v, std::min(k, S / w));
      |                                           ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note:   candidate expects 1 argument, 2 provided