제출 #764499

#제출 시각아이디문제언어결과실행 시간메모리
764499Peter2017Knapsack (NOI18_knapsack)C++17
37 / 100
2 ms468 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define pill pair<int,ll> #define mem(a, b) memset(a, b, sizeof(a)) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) using namespace std; const int N = 1e5 + 5; const int S = 1e5 + 5; const ll oo = 1e17; template <typename T1, typename T2> bool maxi(T1 &a, T2 &b){if (a < b){a = b; return 1;} return 0;} template <typename T1, typename T2> bool mini(T1 &a, T2 &b){if (a > b){a = b; return 1;} return 0;} int n, s; vector <int> v, w, k; bool ar; vector <vector<ll>> f; ll ans; int main(){ cin.tie(0)->sync_with_stdio(0); cin >> s >> n; v.assign(n + 1, 0); w.assign(n + 1, 0); k.assign(n + 1, 0); for (int i = 1; i <= n; i++){ cin >> v[i] >> w[i] >> k[i]; } f.assign(2, vector <ll> (s + 2, 0)); for (int i = 1; i <= n; i++){ ar ^= 1; for (int j = 0; j <= s; j++){ f[ar][j] = f[ar ^ 1][j]; int l = 1, r = k[i]; while (l <= r){ int m = (l + r) >> 1; if (w[i] * m > j){ r = m - 1; continue; } ll tmp = f[ar ^ 1][j - w[i] * m] + 1ll * v[i] * m; if (maxi(f[ar][j], tmp)){ l = m + 1; } else r = m - 1; } } } for (int j = 0; j <= s; j++) maxi(ans, f[ar][j]); cout << ans; }
#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...