Submission #1203466

#TimeUsernameProblemLanguageResultExecution timeMemory
1203466mehraliiKnapsack (NOI18_knapsack)C++20
73 / 100
1092 ms16316 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define ins insert
#define F first
#define S second
#define MAXN 1000005
#define LOG (int)log2(MAXN)+1

const int INF = 1e18;
const int MOD = 998244353;
const double EPS = 1e-8;

void solve() {
	int S, n;
	cin >> S >> n;
	vector<int> p, w;
	for(int i = 0; i < n; i++){
		int x, y, z;
		cin >> x >> y >> z;
		int c = 1;
		while(c<z){
			z -= c;
			p.pb(c*x);
			w.pb(c*y);
			c *= 2;
		}
		p.pb(z*x);
		w.pb(z*y);
	}
	vector<int> dp(S+1, 0);
	for(int i = 0; i < p.size(); i++){
		for(int j = S; j >= w[i]; j--){
			dp[j] = max(dp[j], dp[j-w[i]]+p[i]);
		}
	}
	cout << dp[S] << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
    int t = 1;
//    cin >> t;
	for(int i = 1; i <= t; i++){
		//cout << "Case " << i << ": ";
		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...