Submission #1023612

#TimeUsernameProblemLanguageResultExecution timeMemory
1023612vjudge1Knapsack (NOI18_knapsack)C++17
37 / 100
1041 ms468 KiB
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("Ofast") #define pii pair <int, int> #define pb push_back #define pp pop_back #define int int64_t #define sc second #define fr first using namespace std; const int T=1e16+7, Y=1e6+7, K=998244353; signed main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n, s, i, j, mx=0, a, b, c; cin >> n >> s; vector <int> v(s+1), dp(n+1); for (i=1; i<=s; i++) { cin >> a >> b >> c; while (c--) { for (j=n; j>=0; j--) { if (j==0 && b<=n) dp[b]=max(dp[b], a); if (dp[j]>0 && j+b<=n) { dp[j+b]=max(dp[j+b], dp[j]+a); } } } } for (i=1; i<=n; i++) { mx=max(dp[i], mx); } cout << mx; }
#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...