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 ull unsigned long long
#define MOD 1000000007
#define MODA 998244353
#define pb push_back
#define sortv(v) sort(v.begin(), v.end())
#define sorta(A, N) sort(A, A + N)
#define debug(x) cerr << #x << " is " << x;
#define rep(i, a, N) for (ll i = a; i < N; i++)
#define f first
#define s second
#define uniq(v) \
{ \
sort(v.begin(), v.end()); \
v.erase(unique(v.begin(), v.end()), v.end()); \
}
#define speed \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
void solve(ll tcase)
{
ll S, N, maxi = 0;
cin >> S >> N;
ll dp[N + 1][S + 1];
pair<ll, pair<ll, ll> > A[N + 1];
memset(dp, 0, sizeof(dp));
rep(i, 1, N + 1) cin >> A[i].f >> A[i].s.f >> A[i].s.s;
A[0].f = A[0].s.f = A[0].s.s = 0;
sorta(A, N + 1);
rep(n, 1, N + 1)
{
ll V = A[n].f, W = A[n].s.f, K = A[n].s.s;
rep(w, 1, S + 1)
{
dp[n][w] = dp[n - 1][w];
rep(k, 1, K + 1)
{
if (w - k * W < 0)
break;
if (dp[n][w] < dp[n - 1][w - k * W] + k * V)
dp[n][w] = dp[n - 1][w - k * W] + k * V;
else
break;
}
maxi = max(maxi, dp[n][w]);
}
}
cout << maxi;
}
int main()
{
speed;
ll t = 1;
rep(i, 1, t + 1)
solve(i);
}
# | 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... |