Submission #866376

#TimeUsernameProblemLanguageResultExecution timeMemory
866376phuxtrohhgKnapsack (NOI18_knapsack)C++14
100 / 100
43 ms4908 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<ll, ll> #define st first #define nd second #define all(x) (x).begin(), (x).end() #define mp(x) make_pair(x) #define file "test" using namespace std; const double PI = 2 * acos(0); const long long INF = 1e18; const long long N = 2e6 + 5; ll s, n; ll dp[N]; vector<pii> w[3005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for (ll i = 1; i <=n; i++) { ll v, wai, k; cin >> v >> wai >> k; w[wai].push_back({v, k}); } for (ll i = 1; i <= s; i++) { if (!w[i].size()) continue; sort(all(w[i]), greater<pii>()); ll curw = i; for (ll r = 0; r < w[i].size(); r++) { if (curw > s) break; for (ll sl = 1; sl <= w[i][r].nd && curw <= s; sl++, curw += i) for (ll j = s; j >= i * sl; j--) dp[j] = max(dp[j], dp[j - i] + w[i][r].st); } } cout << dp[s]; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:37:30: 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]
   37 |             for (ll r = 0; r < w[i].size(); r++)
      |                            ~~^~~~~~~~~~~~~
#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...