제출 #551913

#제출 시각아이디문제언어결과실행 시간메모리
551913training4usacoKnapsack (NOI18_knapsack)C++11
12 / 100
1 ms352 KiB
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; #define MAXV 1000005 #define MAXN 100005 #define MAXS 2005 #define INF 1000000009 long long s, n; long long v[MAXN], w[MAXN], k[MAXN]; long long dp[MAXS]; vector<pair<long long, long long>> obj[MAXS]; int main() { cin >> s >> n; for (int i = 1; i <= n; ++i) { cin >> v[i] >> w[i] >> k[i]; } long long mx = -INF; for(int i = 1; i <= n; ++i) { mx = max(mx, k[i]); } for (int i = 1; i <= n; i++) { obj[w[i]].push_back({v[i], k[i]}); } for (int i = 0; i <= s; i++) { if (obj[i].size() == 0) { continue; } sort(obj[i].begin(), obj[i].end()); int id = 0; for (int j = 0; j * i < s; j++) { if (id >= obj[i].size()) { break; } for (int k = s; k >= i; k--) { dp[k] = max(dp[k], dp[k - i] + obj[i][id].first); } --obj[i][id].second; if (obj[i][id].second == 0) { ++id; } } } cout << dp[s] << endl; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             if (id >= obj[i].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...