Submission #866372

#TimeUsernameProblemLanguageResultExecution timeMemory
866372phuxtrohhgKnapsack (NOI18_knapsack)C++14
0 / 100
2 ms600 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[2005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for (int i = 1; i <=n; i++) { ll v, wai, k; cin >> v >> wai >> k; w[wai].push_back({v, k}); } for (int i = 1; i <= s; i++) { if (!w[i].size()) continue; sort(all(w[i])); ll curw = i; for (int r = 0; r < w[i].size(); r++) { if (curw > s) break; for (int sl = 1; sl <= w[i][r].nd; sl++, curw += i) for (int j = s; j >= i * sl; j--) dp[j] = max(dp[j], dp[j - i * sl] + w[i][r].st * sl); } // cout << i <<'\n'; // for (int i = 1; i <=s; i++) // cout << dp[i] <<' '; // cout << '\n'; } // for (int i = 1; i <=n; i++) // { // for (int j = 1; j <= s; j++) // cout << dp[i][j] <<' '; // cout << '\n'; // } cout << dp[s]; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:36:31: 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]
   36 |             for (int 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...