Submission #1218810

#TimeUsernameProblemLanguageResultExecution timeMemory
1218810ladnooooKnapsack (NOI18_knapsack)C++20
12 / 100
2 ms1352 KiB
#include <bits/stdc++.h> using namespace std; //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") #define int long long #define pb push_back const int maxN = 2e3 + 7; int dp[maxN][maxN]; void solveStupid() { int s, n; cin >> s >> n; map<int, vector<pair<int, int>>> w; for(int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; w[b].pb({a, c}); } int k = 0; for(auto &[key, value] : w) { k++; sort(value.begin(), value.end(), greater<pair<int, int>>()); for(int i = 0; i <= s; i++) { int plus = 0, cur = 0, type = 0, cnt = 0; while((cnt + 1) * key <= i && type < value.size()) { cnt++; plus += value[type].first; dp[k][i] = max(dp[k - 1][i], plus + dp[k - 1][i - cnt * key]); cur++; if(cur == value[type].second) { type++; cur = 0; } } } } int mx = 0; for(int i = 0; i <= s; i++) { mx = max(dp[k][i], mx); } cout << mx << '\n'; } signed main() { //freopen("input.txt", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { solveStupid(); } }
#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...