제출 #1005788

#제출 시각아이디문제언어결과실행 시간메모리
1005788pete555Knapsack (NOI18_knapsack)C++17
100 / 100
73 ms35096 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pf push_front #define pi pair<int,int> const int MOD = 1e9+7; int main(){ cin.tie(0)->sync_with_stdio(false); int S, N; cin >> S >> N; map<int, vector<pi>> bw; for(int i=0; i<N; i++){ int v, w, k; cin >> v >> w >> k; bw[w].pb({v, k}); } vector<vector<ll>> dp(bw.size()+1, vector<ll>(S+1, -1e9)); dp[0][0] = 0; int at = 1; for(auto &[w, item]: bw){ sort(item.begin(), item.end(), greater<pi>()); for(int i=0; i<=S; i++){ dp[at][i] = dp[at-1][i]; int cur = 0; int type_at = 0; int used = 0; ll profit = 0; while((cur+1)*w <= i and type_at < item.size()){ cur++; profit += item[type_at].first; dp[at][i] = max(dp[at][i], dp[at-1][i-cur*w] + profit); used++; if(used == item[type_at].second){ used = 0; type_at++; } } } at++; } cout << *max_element(dp.back().begin(), dp.back().end()) << '\n'; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:33:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    while((cur+1)*w <= i and type_at < item.size()){
      |                             ~~~~~~~~^~~~~~~~~~~~~
#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...