제출 #464288

#제출 시각아이디문제언어결과실행 시간메모리
464288vbeeKnapsack (NOI18_knapsack)C++17
73 / 100
183 ms262148 KiB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>
#define fi first
#define se second
#define TASK ""
#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define pb push_back
#define MASK(i) (1 << (i))
#define BIT(x, i) ((x >> (i)) & 1)

using namespace std;

const int oo = 1e9 + 7;
const ll loo = (ll)1e18 + 7;
const int N = 1e5 + 7;
const int S = 2007;
int dp[N][S], w[N], v[N], k[N], n, s;
void maximize(int &a, int b){
	if (a < b) a = b;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> s >> n;
	for (int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i];
	for (int i = 0; i < n; i++){
		for (int sum = 0; sum <= s; sum++){
			for (int z = 0; z <= k[i + 1]; z++){
				if (sum + w[i + 1] * z > s) break;
				maximize(dp[i + 1][sum + w[i + 1] * z], dp[i][sum] + v[i + 1] * z);
			}
		}
	}
	int res = 0;
	for (int i = 0; i <= s; i++) maximize(res, dp[n][i]);
	cout << res;
	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...