제출 #955971

#제출 시각아이디문제언어결과실행 시간메모리
955971NeltKnapsack (NOI18_knapsack)C++17
73 / 100
1051 ms600 KiB
#include <bits/stdc++.h> #define ll long long #define endl "\n" using namespace std; void solve() { ll s, n; cin >> s >> n; vector<ll> items[s + 1]; while (n--) { ll v, w, k; cin >> v >> w >> k; k = min(k, s / w); while (k--) items[w].push_back(v); sort(items[w].begin(), items[w].end(), greater()); while (items[w].size() * w > s) items[w].pop_back(); } ll dp[s + 1]; for (ll i = 0; i <= s; i++) dp[i] = 0; for (ll i = 1; i <= s; i++) for (ll j : items[i]) for (ll k = s - i; k >= 0; k--) dp[k + i] = max(dp[k + i], dp[k] + j); cout << *max_element(dp, dp + s + 1) << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); ll t = 1; // precomp(); // cin >> t; for (ll i = 1; i <= t; i++) solve(); cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n"; }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:19:36: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   19 |         while (items[w].size() * w > s)
      |                ~~~~~~~~~~~~~~~~~~~~^~~
#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...