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>
#define ll long long
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 1e5+5;
const ll inf = 100000000000000000;
vl v(sz), w(sz), k(sz), dp(sz);
vector<array<ll, 2>> A[2005];
void solve(){
ll S, n, i, j;
cin >> S >> n;
for(i = 1; i <= n; i++){
cin >> v[i] >> w[i] >> k[i];
A[w[i]].pb({v[i], k[i]});
}
for(i = 1;i <= S; i++){
if(A[i].empty()){continue;}
ll hi = S / i;
while(hi-- && (!A[i].empty())){
for(j = S; j >= i; j--){
if(dp[j - i] + A[i].back()[0] > dp[j]){
dp[j] = dp[j - i] + A[i].back()[0];
}
}
A[i].back()[1]--;
if(A[i].back()[1] == 0){A[i].pop_back();}
}
}
ll ans = 0;
for(i = 1; i <= S; i++){
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
int main() {
ll t = 1;
///cin >> t;
while(t--){
solve();
}
}
# | 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... |