Submission #1157638

#TimeUsernameProblemLanguageResultExecution timeMemory
1157638arkanefuryKnapsack (NOI18_knapsack)C++17
73 / 100
1095 ms2496 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define in insert #define lb lower_bound #define F first #define S second #define sz size() #define int long long #define all(v) v.begin(),v.end() #define FOR1(x, n) for(int j = x; j <= n; j ++) #define FOR(x, n, m, d) for(int x = n; x <= m; x += d) #define FORR(x, n, m, d) for(int x = n; x >= m; x -= d) #define nikita ios_base::sync_with_stdio(0), cin.tie(0); const int N = 1e5+5; int n,m,k,sum=0,x,y, ans, r, cnt, l, mod = 1e9+7, dp[N]; string s, str; void solve(){ cin >> m >> n; ans = 0; vector<pair<int, int>>v[2050]; FOR(ok,1,n,1){ int cost, worth, skoka; cin >> cost >> worth >> skoka; skoka = min(skoka, (m+worth-1)/worth); v[worth].pb({cost, skoka}); } FOR(i, 1, m, 1){ for(auto ok : v[i]){ FORR(j, m, i, 1){ k = 0; while(1){ if(j >= i * k)dp[j] = max(dp[j], dp[j - i*k] + ok.F * k); else break; if(k==ok.S)break; k++; } } } } FOR(i, 1, m, 1)ans = max(ans, dp[i]); cout<<ans; } signed main(){ nikita int tt = 1; if(!tt)cin >> tt; FOR(i, 1, tt, 1)solve(); }
#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...