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 = 2e3 + 1;
long long dp[N][N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int s, n;
cin >> s >> n;
vector<long long> f[s+1];
while (n--)
{
int v, w, k, cur = 1;
cin >> v >> w >> k;
while (k >= cur)
{
k -= cur;
if (1ll*w*cur <= s) f[w*cur].push_back(1ll*v*cur);
cur *= 2;
}
if (k > 0 && 1ll*w*k <= s) f[w*k].push_back(1ll*v*k);
}
vector<long long> p[s+1];
for (int i = 1; i <= s; i++)
{
sort(f[i].begin(), f[i].end(), greater<long long>());
p[i].push_back(0);
for (int j = 0; j < (int)f[i].size(); j++) p[i].push_back(p[i].back()+f[i][j]);
}
for (int i = 1; i <= s; i++)
for (int j = 1; j <= s; j++)
{
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
for (int k = 0; k*j <= i && k <= (int)f[j].size(); k++)
dp[i][j] = max(dp[i][j], dp[i-k*j][j-1]+p[j][k]);
}
cout << dp[s][s];
return 0;
}
# | 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... |