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;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, int> pill;
typedef vector<pill> vpill;
typedef vector<vpill> vvpill;
int main()
{
//freopen("..\\io\\input.txt", "r", stdin);
//freopen("..\\io\\output.txt", "w", stdout);
int s, n; cin >> s >> n;
vll k(n+1, 0);
vll v(n+1, 0);
vll w(n+1, 0);
vvpill dp(n+1, vpill(s+1, {0,0}));
for(int i = 1; i <= n; i++)
{
cin >> v[i] >> w[i] >> k[i];
}
for(int i = 1; i <= n; i++)
{
for(int m = 1; m <= w[i]; m++)
{
for(int j = m; j <= s; j+=w[i])
{
if(dp[i][j- w[i]].second < k[i] && j - w[i] >= 0)
{
if(dp[i][j].first < dp[i][j-w[i]].first + v[i] || (dp[i][j].first == dp[i][j-w[i]].first + v[i] && dp[i][j-w[i]].second + 1 < dp[i][j].second))
{
dp[i][j] = {dp[i][j-w[i]].first + v[i], dp[i][j-w[i]].second + 1};
}
}
if(dp[i][j].first <= dp[i-1][j].first)
{
dp[i][j] = dp[i-1][j];
dp[i][j].second = 0;
}
if(dp[i][j].first < dp[i][j-1].first || (dp[i][j].first == dp[i][j-1].first && dp[i][j].first > dp[i][j-1].second))
dp[i][j] = dp[i][j-1];
}
}
}
/*for(int i = 1; i <= n; i++)
{
for(int j = 0; j <= s; j++)
{
cout << dp[i][j].first << ", " << dp[i][j].second << " ";
}
cout << "\n";
}*/
cout << dp[n][s].first;
}
# | 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... |