제출 #471044

#제출 시각아이디문제언어결과실행 시간메모리
471044EvangKnapsack (NOI18_knapsack)C++17
17 / 100
2 ms204 KiB
#include "bits/extc++.h" #define int ll using namespace std; #ifdef LOCAL #define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el #else #define dout(x) #endif #define inf 1000000000 #define llinf 1000000000000000000ll #define uset unordered_set #define umap unordered_map #define mp(a,b) make_pair(a,b) #define mt(x...) make_tuple(x) #define eb(x...) emplace_back(x) #define pb(x) push_back(x) #define ff first #define ss second const char el = '\n', sp = ' '; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; template<class T> using minpq = priority_queue<T, vector<T>, greater<T>>; const int S = 2005; int s, n, dp[S]; void fun(int a, int c){ for(int i = s; i >= c; --i) dp[i] = max(dp[i], dp[i-c] + a); } int32_t main() { cin.tie(nullptr)->sync_with_stdio(false); #ifdef LOCAL freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); #endif cin >> s >> n; while(n--){ int a, c, k; cin >> a >> c >> k; bool cur = 0; while(k>0 && c <= s){ if(k&1) { fun(a, c); cur = 0; } else if(cur) fun(a, c); else{ fun(a, c); fun(a, c); cur = 1; } k/=2; a *= 2; c *= 2; } } cout << dp[s]; }
#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...