제출 #906217

#제출 시각아이디문제언어결과실행 시간메모리
906217trinhbaongoc3006Knapsack (NOI18_knapsack)C++17
100 / 100
50 ms3920 KiB
#include <bits/stdc++.h> #define INF int64_t(1e9) #define pii pair <int, int> #define pll pair <long long, long long> #define file "test" using namespace std; const int nmax=2005; const int MOD = 1e9 + 7; int s, n; vector <pii> adj[nmax]; long long dp[nmax]; int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); //freopen(file".inp","r",stdin); //freopen(file".out","w",stdout); cin >> s >> n; for (int i=1;i<=n;i++) { int w, v, k; cin >> v >> w >> k; adj[w].push_back({v,k}); } for (int i=1;i<=s;i++) { if (adj[i].size() == 0) continue; sort(adj[i].begin(), adj[i].end(), greater <pii> ()) ; int id = 0; for (int j=0;j*i<s;j++) { if (id >= adj[i].size()) break; for (int k=s;k>=i;k--) { dp[k] = max(dp[k], dp[k-i] + adj[i][id].first); } adj[i][id].second--; if (adj[i][id].second == 0) id++; } } cout << dp[s] ; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:33:20: 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 |             if (id >= adj[i].size()) break;
      |                 ~~~^~~~~~~~~~~~~~~~
#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...