Submission #944410

#TimeUsernameProblemLanguageResultExecution timeMemory
944410cotKnapsack (NOI18_knapsack)C++14
100 / 100
185 ms248360 KiB
#include <iostream> #include <algorithm> #include <vector> #define int long long #define ff first #define ss second #define pb push_back #define pp pop_back #define all(x) x.begin(),x.end() #define pii pair<int,int> #define r0 return 0 using namespace std; const int N = 2005; int s, n, raod[N], w, vv, r, cnt, cur, ans; vector <pii> v[N]; int dp[N*12][N]; vector <pii> g; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for (int i = 1; i <= n; i++) { cin >> vv >> w >> r; v[w].pb({vv,r}); raod[w] += r; } for (int i = 1; i <= s; i++) { sort(all(v[i])); reverse(all(v[i])); cnt = 0; cur = 0; for (int j = 1; j <= min(raod[i], s / i); j++) { cnt++; g.pb({i, v[i][cur].ff}); if (v[i][cur].ss == cnt) cur++, cnt = 0; } } n = g.size(); for (int i = 1; i <= n; i++) { //cout<<g[i - 1].ff <<" "<<g[i - 1].ss<<endl; for (int j = 0; j <= s; j++) { dp[i][j] = dp[i - 1][j]; if (j < g[i - 1].ff) continue; dp[i][j] = max (dp[i - 1][j], dp[i - 1][j - g[i - 1].ff] + g[i - 1].ss); ans = max(ans, dp[i][j]); } } cout << ans << endl; r0; }
#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...