Submission #847771

#TimeUsernameProblemLanguageResultExecution timeMemory
847771vjudge1Knapsack (NOI18_knapsack)C++17
37 / 100
1 ms856 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; #define FOR(i, a) for (int i=0; i<(a); i++) #define all(x) x.begin(), x.end() #define gcd __gcd #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second //const int dr[4] = {-1, 0, 1, 0}, dc[4] = {0, 1, 0, -1}; const int N = 2001; ll dp[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; vector<pair<int, ll>> vec; while(n--){ ll v; int w, a; cin >> v >> w >> a; for(int i = 0; i <= 30; ++i){ if(a >= (1 << i)){ a -= (1 << i); vec.emplace_back(w * (1 << i), v * (1 << i)); } else{ vec.emplace_back(w * a, v * a); break; } } } memset(dp, -1, sizeof dp); dp[0] = 0; for(pair<int, ll> &it : vec) for(int j = s; j >= it.fi; --j) if(dp[j - it.fi] != -1) dp[j] = max(dp[j], dp[j - it.fi] + it.se); cout << *max_element(dp, dp + s + 1); 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...