제출 #1023691

#제출 시각아이디문제언어결과실행 시간메모리
1023691vjudge1Knapsack (NOI18_knapsack)C++17
49 / 100
1073 ms472 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; 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> dp(n+1); for (i=1; i<=s; i++) { cin >> a >> b >> c; c=min(n, 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=0; 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...