Submission #1201631

#TimeUsernameProblemLanguageResultExecution timeMemory
1201631spampotsKnapsack (NOI18_knapsack)C++20
12 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpii; const int MOD = 1e9 + 7; const int INF = INT_MAX; const ll LINF = LLONG_MAX; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define pb push_back #define mp make_pair #define fi first #define se second #define all(v) v.begin(), v.end() #define rep(i, a, b) for(int i = a; i < b; ++i) bool comp(pii a, pii b){ return a.fi*b.se > a.se*b.fi; } void solve() { int s, n; cin >> s >> n; vector<pair<int ,int>> f; rep(i, 0, n){ int v ,w, k; cin >> v >> w >> k; int c(1); while(k > c && c*w <= s){ k -= c; f.pb({c*w, c*v}); c *= 2; } if(c*w <= s){ f.pb({k*w, k*v}); } } sort(f.begin(), f.end(), comp); vector<int> dp(s+1, -INF); dp[0] = 0; for (int i = 0; i < min(s*60, (int)f.size()); ++i) for (int j = s; j >= f[i].fi; --j) dp[j] = max(dp[j], dp[j - f[i].fi] + f[i].se); int ans = 0; for (int i = 0; i <= s; ++i) { ans = max(ans, dp[i]); } cout << ans << endl; } int main() { fast; int t = 1; while(t--) { 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...