Submission #965803

#TimeUsernameProblemLanguageResultExecution timeMemory
965803vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
61 ms35344 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define stp(n) fixed<<setprecision(n) #define flash cin.tie(0); cin.sync_with_stdio(0); #define el '\n' #define Point pair<double, double> // Define Point as a pair of doubles using namespace std; //// #pragma GCC optimize("03") #pragma GCC target("tune=native") #pragma GCC optimize("unroll-loops") const int inf = 1e9, N = 2e3 + 9, mod = 998244353, M = 6e3; ll dp[N][N]; vector<vector<pair<int, int>>> W(N); void testCase() { int n, s; cin >> s >> n; for (int i = 0; i < n; ++i) { int vi, wi, ki; cin >> vi >> wi >> ki; W[wi].push_back({vi, ki}); } for (int i = 1; i <= s; i++)sort(W[i].rbegin(), W[i].rend()); for (int w = s; w >= 1; w--) { for (int rem = 0; rem <= s; rem++) { ll &ans = dp[w][rem]; ans = dp[w + 1][rem]; ll sum = 0, cnt = 0, l = 0; for (int i = 1; i <= (rem / w); i++) { if (l == W[w].size())break; cnt++, sum += W[w][l].first; ans = max(ans,dp[w + 1][rem - i * w] + sum); if (cnt == W[w][l].second)l++, cnt = 0; } } } cout<<dp[1][s]; } int main() { // freopen("feast.in", "r", stdin); // freopen("feast.out", "w", stdout); flash; int t = 1; //cin >> t; while (t--) { testCase(); } }

Compilation message (stderr)

knapsack.cpp: In function 'void testCase()':
knapsack.cpp:38:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |                 if (l == W[w].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...