| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1003675 | ypratik | Knapsack (NOI18_knapsack) | C++17 | 138 ms | 262144 KiB |
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 int long long
#define nline "\n"
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const int N = 0;
void Solve()
{
int s, n;
cin >> s >> n;
vector<pair<int, int>> a;
a.push_back({0, 0});
for (int i = 0; i < n; ++i)
{
int x, y, z;
cin >> x >> y >> z;
while (z--)
{
a.push_back({x, y});
}
}
n=a.size();
vector<vector<int>> dp(n + 1, vector<int>(s + 1, -INF));
// vector<int> dp(s + 1, -INF);
dp[0][0] = 0;
for (int i = 1; i <= a.size(); ++i)
{
for (int j = 0; j < s + 1; ++j)
{
dp[i][j]=dp[i-1][j];
if (j - a[i].second >= 0)
{
dp[i][j] = max(dp[i][j], dp[i-1][j - a[i].second] + a[i].first);
}
}
}
int ans = 0;
for (int i = 0; i < s+1; ++i)
{
ans = max(ans, dp[n][i]);
}
cout << ans << nline;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#ifdef SIEVE
sieve();
#endif
#ifdef NCR
init();
#endif
int t = 1;
while (t--) Solve();
return 0;
}Compilation message (stderr)
| # | 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... | ||||
