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;
#define ll long long
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;
#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second
#define mp make_pair
void solve(){
int s,n;
cin>>s>>n;
vi v(n);
vi w(n);
vi k(n);
fori(i,n){
cin>>v[i]>>w[i]>>k[i];
}
vvi dp(2,vi(s+1,0));
int l=1;
rep(i,1,n){
l=!l;
rep(j,1,s){
int t=0;
dp[!l][j] = dp[l][j];
while(t<=k[i-1] && j-t*w[i-1]>=0){
dp[!l][j] = max( dp[!l][j], dp[l][j-t*w[i-1]] + t*v[i-1]);
t++;
}
}
}
int ans=0;
fori(i,s+1){
ans = max(ans,dp[n%2][i]);
}
// fori(i,n+1){
// fori(j,s+1){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int 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... |