Submission #1294844

#TimeUsernameProblemLanguageResultExecution timeMemory
1294844fatelessKnapsack (NOI18_knapsack)C++20
12 / 100
1 ms580 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]); vc<ll> dp(s + 1, -inf); dp[0] = 0; int r = 0; for(int i = 1; i <= n; i++) { while(cnt[i]--) { for(int x = r + w[i]; x >= w[i]; x--) dp[x] = max(dp[x], dp[x - w[i]] + c[i]); r = min(1ll*s, r + w[i]); } } 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...