Submission #1070507

#TimeUsernameProblemLanguageResultExecution timeMemory
1070507ndquangKnapsack (NOI18_knapsack)C++17
73 / 100
1096 ms596 KiB
#include <bits/stdc++.h> using namespace std; /** Author: Nguyen Duy Quang **/ #define test int T; cin >> T; while(T--) #define all(x) (x).begin(), (x).end() #define Bit(x, y) ((x >> y) & 1) #define int long long #define pb push_back #define fi first #define sc second #define submitFile(Task) freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); using pii = pair<int, int>; using ull = unsigned long long; const int INF = (int)1e18, MOD1 = (int)1e9 + 7, MOD2 = (int)998244353; template<class X, class Y> void maximize(X &a, const Y &b) { a = (a < b) ? b : a; } template<class X, class Y> void minimize(X &a, const Y &b) { a = (a > b) ? b : a; } template<class T> void add(T& a, T b) { a += b; if(a >= MOD1) a -= MOD1; } template<class T> void sub(T& a, T b) { a -= b; if(a <= 0) a += MOD1; } template<class T> T Abs(const T& a) { return (a < 0 ? -a : a); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l, int r) { return l + rng() % (r - l + 1); } void sinhTest(int itest) { ofstream cout(("test" + to_string(itest) + ".inp").c_str()); } void solveTest(int itest) { ifstream cin(("test" + to_string(itest) + ".inp").c_str()); ofstream cout(("test" + to_string(itest) + ".out").c_str()); } ///END OF TEMPLATE signed main() { cin.tie(0)->ios_base::sync_with_stdio(0); int s, n; cin >> s >> n; vector<int> dp(s + 1, 0); for(int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; for(int j = 1; k > 0; j <<= 1) { int num = min(j, k); k -= num; for(int x = s; x >= num * w; x--) maximize(dp[x], dp[x - num * w] + num * v); } } int ans = 0; for(int i = 0; i <= s; i++) maximize(ans, dp[i]); cout << ans; return 0; }
#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...