제출 #503528

#제출 시각아이디문제언어결과실행 시간메모리
503528CantfindmeKnapsack (NOI18_knapsack)C++17
100 / 100
57 ms4956 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int> pi; #define f first #define s second #define FAST ios_base::sync_with_stdio(0); cin.tie(0); #define all(x) x.begin(),x.end() typedef pair<int, pi> pii; const int maxn = 2010; const int INF = LLONG_MAX/2; const int mod = 1e9+7; int S, n; vector <pi> items[maxn]; int dp[maxn]; void tryitem(int w, int v) { for (int i = S; i - w >= 0;i--) { dp[i] = max(dp[i], dp[i-w] + v); } } int32_t main() { FAST cin >> S >> n; for (int i =0;i<n;i++) { int v,w,k; cin >> v >> w >> k; items[w].push_back(pi(v,k)); } for (int i =1;i<=S;i++) { sort(all(items[i]), greater<pi>()); } for (int i =1;i<=S;i++) { int co = 0; for (auto [v, k] : items[i]) { for (int j = 0;j<k;j++) { tryitem(i, v); co++; if (co * i > S) goto dd; } } dd:; } cout << dp[S]; }
#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...