Submission #595364

#TimeUsernameProblemLanguageResultExecution timeMemory
595364yaroslav06Knapsack (NOI18_knapsack)C++14
12 / 100
1 ms340 KiB
#include <iostream> #include <algorithm> const int N = 2001, M = 1e5; using namespace std; typedef long long ll; int s, n; pair<int, pair<int, int>> d[M]; bool comp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b){ return a.second.first < b.second.first; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int dp[N][2]{}; int sm[N]{}; cin >> s >> n; for(int i = 0; i < n; ++i) cin >> d[i].second.first >> d[i].first >> d[i].second.second; sort(d, d + n, comp); for(int i = 0; i < n; ++i){ int k = d[i].second.second, v = d[i].second.first, w = d[i].first; if(sm[w] >= 2000) continue; sm[w] += min(k * 1ll * w, 2000ll); for(int j = 1; j <= k && j * w <= s; ++j) for(int t = s; t - j * w >= 0; --t) dp[t][1] = max(dp[t][1], dp[t - j * w][0] + j * v); for(int j = 0; j <= s; ++j) dp[j][0] = dp[j][1]; } cout << dp[s][0] << '\n'; }
#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...