#include<iostream>
#include<algorithm>
#include <cmath>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int C;
int n;
cin >> C >> n;
long long v, w, b;
vector<long long> dp(C + 1, 0);
for(int i = 0; i < n; i++){
int x = 1;
cin >> v >> w >> b;
//Decomposição Binaria
while(b > x){
long long total_w = x * w;
long long total_v = x * v;
//Processa dp conforme insere os items
for (int c = C; c >= total_w; c--) {
dp[c] = max(dp[c], dp[c - total_w] + total_v);
}
b -= x;
x = x << 1;
}
//Resto da decomposição
long long total_w = b * w;
long long total_v = b * v;
for (int c = C; c >= total_w; c--) {
dp[c] = max(dp[c], dp[c - total_w] + total_v);
}
}
cout << dp[C] << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |