제출 #1271598

#제출 시각아이디문제언어결과실행 시간메모리
1271598annnKnapsack (NOI18_knapsack)C++20
73 / 100
3 ms328 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 = 103, mxw = 1e4 + 3; int k[mx], a[mx], b[mx]; vector<int> val[mxw]; ll dp[mxw]; void Prepare() { cin >> w >> n; rep(i, 1, n) cin >> b[i] >> a[i] >> k[i]; } void COOOOK() { for (int e = 1; e <= w; e++) { priority_queue<ii> pq; rep(i, 1, n) { if (a[i] == e) pq.push({b[i], k[i]}); } 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; }

컴파일 시 표준 에러 (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...