이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
// author: aykhn
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define mpr make_pair
#define eb emplace_back
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define ins insert
#define int ll
#define inf 0x3F3F3F3F
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount
const int MXN = 2e3 + 5;
int dp[MXN];
vector<array<int, 2>> a[MXN];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int s, n;
cin >> s >> n;
for (int i = 1; i <= n; i++)
{
int v, w, k;
cin >> v >> w >> k;
a[w].pb({v, k});
}
for (int i = 1; i <= s; i++)
{
sort(all(a[i]));
int take = s / i;
while (take-- && !a[i].empty())
{
for (int j = s; j >= i; j--)
{
dp[j] = max(dp[j], dp[j - i] + a[i].back()[0]);
}
if (!--a[i].back()[1]) a[i].pop_back();
}
}
cout << *max_element(dp, dp + MXN) << '\n';
}
# | 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... |