Submission #1271600

#TimeUsernameProblemLanguageResultExecution timeMemory
1271600annnKnapsack (NOI18_knapsack)C++20
100 / 100
37 ms3804 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define pb push_back #define ff first #define ss second #define ii pair<int, int> #define vi vector<int> #define vii vector<pair<int, int>> #define yes cout << "YES\n" #define no cout << "NO\n" #define mii map<int, int> #define rep(i, a, b) for (int i = a; i <= b; i++) #define all(a, len) (a) + 1, (a) + len + 1 #define vall(a) (a).begin(), a.end() #define _READ(name) freopen(name, "r", stdin) #define _WRITE(name) freopen(name, "w", stdout) const int INF = 4e18; const int MOD = 1e9 + 7; int n, w; const int mx = 1e6 + 3, mxw = 2003; int k[mx], a[mx], b[mx]; vector<int> val[mxw]; vii wei[mxw]; ll dp[mxw]; void Prepare() { cin >> w >> n; rep(i, 1, n) { cin >> b[i] >> a[i] >> k[i]; wei[a[i]].pb({b[i], k[i]}); } } void COOOOK() { for (int e = 1; e <= w; e++) { priority_queue<ii> pq; for (auto it: wei[e]) pq.push(it); for (int _ = 1; _ <= w/e && pq.size(); _++) { ii ff = pq.top(); pq.pop(); val[e].pb(ff.ff); if (ff.ss >= 2) pq.push({ff.ff, ff.ss - 1}); } } // dp[i] = max val voi khoi luong toi da = i for (int i = 1; i <= w; i++) { for (auto it: val[i]) { for (int j = w; j >= i; j--) { dp[j] = max(dp[j], dp[j-i]*1ll + it*1ll); } } } cout << *max_element(dp+1, dp+w+1); } void Eat() { } void Wash() { } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int TEST = 1; // cin >> TEST; while (TEST--) { Prepare(); COOOOK(); Eat(); Wash(); } return 0; }

Compilation message (stderr)

knapsack.cpp:20:17: warning: overflow in conversion from 'double' to 'int' changes value from '4.0e+18' to '2147483647' [-Woverflow]
   20 | const int INF = 4e18;
      |                 ^~~~
#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...