This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 1, S = 1e5+ 1;
int n, s;
vector<vector<long long>> dp(N, vector<long long>(S));
vector<int> h(N), w(N), k(N);
int main(){
cin >> s >> n;
for(int i = 1; i <= n; i++){
cin >> w[i] >> h[i] >> k[i];
}
long long pra = h[1], car = w[1];
while(k[1] && pra <= s){
dp[1][pra] = car;
pra += h[1];
car += w[1];
k[1]--;
}
for(int i = 2; i <= n; i++){
for(int x = 1; x <= s; x++){
dp[i][x] = max(dp[i][x], dp[i - 1][x]);
long long acum = h[i], pr = w[i], zaz = k[i];
while(acum <= s && zaz){
if(x >= acum && dp[i][x] < dp[i - 1][x - acum] + pr){
dp[i][x] = dp[i - 1][x - acum] + pr;
}
acum += h[i];
pr += w[i];
zaz--;
}
}
}
long long ans = 0;
for(int i = 1; i <= s; i++){
ans = max(ans, dp[n][i]);
}
cout << ans;
}
# | 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... |