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 forn(i, n) for (int i = 0; i < n; i++)
#define ull unsigned long long
#define ll long long
#define SPEED \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
using namespace std;
const int N = 1000 + 13;
const int maxa = 1e6 + 13;
const ll mod = 998244353;
void prestart() {}
ll dp[maxa];
void start()
{
int s, n;
cin >> s >> n;
ll v[n], w[n], k[n];
forn(i, n) {
cin >> v[i];
cin >> w[i];
cin >> k[i];
}
for (int i = 0; i < n; i++)
{
for (int j = s; j >= 0; j--)
{
for(int l = 0; l <= min(k[i], j / w[i]); l++) {
dp[j] = max(dp[j], dp[j - w[i] * l] + v[i] * l);
}
}
}
cout << dp[s] << "\n";
}
signed main()
{
SPEED;
int t = 1;
prestart();
// cin >> t;
while (t--)
{
start();
}
}
# | 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... |