제출 #999388

#제출 시각아이디문제언어결과실행 시간메모리
999388GasmaskChanKnapsack (NOI18_knapsack)C++17
100 / 100
75 ms36456 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define MAX 2005 int f[MAX][MAX]; map<int, vector<pair<int, int>>> a; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); int s, n; cin >> s >> n; for (int v, w, k, i = 0; i < n; i++) { cin >> v >> w >> k; if (w <= s) { a[w].emplace_back(v, k); } } int i = 0; for (auto &[w, items] : a) { std::sort(items.begin(), items.end(), greater<pair<int, int>>()); ++i; for (int j = 0; j <= s; j++) { f[i][j] = f[i - 1][j]; int cur = 0, num = 0, take = 0, val = 0; while (cur < items.size() && (num + 1) * w <= j) { ++num; val += items[cur].first; f[i][j] = max(f[i][j], f[i - 1][j - num * w] + val); if (++take == items[cur].second) { take = 0; ++cur; } } } } cout << f[i][s]; return 0; }

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

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:29:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             while (cur < items.size() && (num + 1) * w <= 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...