Submission #859446

#TimeUsernameProblemLanguageResultExecution timeMemory
859446dwuyKnapsack (NOI18_knapsack)C++14
0 / 100
1 ms604 KiB
/// dwuy: _,\,,,_\,__,\,,_ #include <bits/stdc++.h> #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL) #define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout) #define fi first #define se second #define endl "\n" #define len(s) int32_t(s.length()) #define MASK(k)(1LL<<(k)) #define TASK "" #define int long long using namespace std; typedef tuple<int, int, int> tpiii; typedef pair<double, double> pdd; typedef pair<int, int> pii; typedef long long ll; const long long OO = 1e18; const int MOD = 1e9 + 7; const int INF = 1e9; const int MX = 100005; int s, n; int a[MX]; int b[MX]; int dp[2005]; vector<pair<int, int>> Max[2005]; void nhap(){ cin >> s >> n; for(int i=1; i<=n; i++){ int v, w, k; cin >> v >> w >> k; Max[w].push_back({v, k}); } } void solve(){ dp[0] = 1; for(int i=1; i<=s; i++){ if(Max[i].size()==0) sort(Max[i].begin(), Max[i].end(), greater<pii>()); for(int j=s; j>=i; j--){ int sum = 0; for(int k=1, t=0, s=1; i*k<=j; k++){ sum += Max[i][t].fi; if(dp[j-i*k]) dp[j] = max(dp[j], dp[j-i*k] + sum); if(s==Max[i][t].se){ s = 1; t++; if(t==(int)Max[i].size()) break; } else s++; } } } int ans = 0; for(int i=1; i<=s; i++) ans = max(ans, dp[i]); cout << ans - 1; } int32_t main(){ fastIO; //file(TASK); nhap(); solve(); return 0; }
#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...