| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1003664 | ypratik | Knapsack (NOI18_knapsack) | C++17 | 1048 ms | 67000 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;
for (int i = 0; i < n; ++i)
{
int x, y, z;
cin >> x >> y >> z;
while (z--)
{
a.push_back({x, y});
}
}
vector<int> dp(s + 1, -INF);
dp[0] = 0;
for (int i = 0; i < a.size(); ++i)
{
for (int j = s; j >= 0; --j)
{
if (j - a[i].second >= 0)
{
dp[j] = max(dp[j], dp[j - a[i].second] + a[i].first);
}
}
}
int ans = 0;
for (int i = 0; i < s + 1; ++i)
{
ans = max(ans, dp[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... | ||||
