| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1330943 | Thanhs | Knapsack (NOI18_knapsack) | C++20 | 38 ms | 2916 KiB |
#include <bits/stdc++.h>
using namespace std;
#define name "TENBAI"
#define fi first
#define se second
#define int long long
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()
mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int SM = 2000 + 5;
const int inf = 1e18;
int n, s, f[SM];
vector<pair<int, int>> v[SM];
void solve()
{
cin >> s >> n;
for (int i = 1; i <= n; i++)
{
int va, w, k;
cin >> va >> w >> k;
v[w].push_back({va, k});
}
f[0] = 0;
for (int i = 1; i <= s; i++)
{
f[i] = -inf;
sort(all(v[i]));
}
for (int i = 1; i <= s; i++)
{
int c = 0;
while (v[i].size() && c < s / i)
{
c++;
int t = v[i].back().fi;
for (int j = s; j >= i; j--)
setmax(f[j], f[j - i] + t);
v[i].back().se--;
if (!v[i].back().se)
v[i].pop_back();
}
}
cout << *max_element(f, f + 1 + s);
}
signed main()
{
if (fopen("in.txt", "r"))
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
else if (fopen(name".inp", "r"))
{
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int tc = 1;
// cin >> tc;
while (tc--)
solve();
}
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... | ||||
