Submission #1294850

#TimeUsernameProblemLanguageResultExecution timeMemory
1294850fatelessKnapsack (NOI18_knapsack)C++20
100 / 100
738 ms2812 KiB
#pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx, avx2, fma") #include <bits/stdc++.h> using namespace std; #define speedup cin.tie(0)->sync_with_stdio(0) #define bitcount(x) __builtin_popcountll(x) #define lla(x) x.rbegin(), x.rend() #define all(x) x.begin(), x.end() #define Tp template<class T> #define pb push_back #define arr array Tp using vc = vector<T>; using pii = pair<int,int>; using ld = long double; using ll = long long; const ll mod = 998244353, N = 501, inf = 1e18;; inline void solve() { int n, s; cin >> s >> n; vc<ll> c(n + 1), w(n + 1), cnt(n + 1); for(int i = 1; i <= n; i++) cin >> c[i] >> w[i] >> cnt[i]; // for(int i = 1; i <= n; i++) cnt[i] = min(cnt[i], s / w[i] + 1); vc<ll> dp(s + 1, -inf); dp[0] = 0; for(int i = 1; i <= n; i++) { ll p = 1; while(cnt[i]){ ll take = min(p, cnt[i]); ll wx = w[i] * take, cx = c[i] * take; for(int x = s; x >= wx; x--) dp[x] = max(dp[x], dp[x - wx] + cx); cnt[i] -= take; p <<= 1; } } cout << *max_element(all(dp)) << '\n'; } signed main() { speedup; solve(); }
#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...