제출 #914013

#제출 시각아이디문제언어결과실행 시간메모리
914013dpsaveslivesKnapsack (NOI18_knapsack)C++17
100 / 100
45 ms2080 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; const int MAX = 2010; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int S,N; cin >> S >> N; vector<pair<int,int>> mp[MAX]; for(int i = 0;i<N;++i){ int v,w,k; cin >> v >> w >> k; mp[w].push_back({v,min(k,S/w)}); } vector<int> dp(S+1,0); for(int i = 1;i<=S;++i){ vector<pair<int,int>> vec = mp[i]; sort(vec.rbegin(),vec.rend()); int cnt = 0; for(int j = 0;j<vec.size();++j){ int v = vec[j].f, k = vec[j].s; while(k--){ for(int l = S;l>=i;l--){ dp[l] = max(dp[l],dp[l-i]+v); } ++cnt; if(cnt*i >= S) break; } if(cnt*i >= S) break; } } cout << dp[S] << "\n"; return 0; }

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

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