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>
#define ii pair <int, int>
#define ll long long
#define llll pair <ll, ll>
#define ld long double
#define ull unsigned long long
#define el "\n"
#define sp " "
#define fi first
#define se second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define __lcm(a, b) (a / __gcd(a, b) * b)
#define sq(x) (x) * (x)
#define sqr(x) sqrtl(x)
#define cbr(x) cbrtl(x)
#define sz(a) (ll)(a.size())
using namespace std;
const ld PI = acos(-1); const int INFI = 1e9 + 7; const ll INFL = 2e18 + 7;
int s, n, w;
ll v, a, curval, curnum, dp[2005], ans;
vector <llll> weight[2005];
void Solve()
{
cin >> s >> n;
for (int i = 1; i <= n; i++)
{
cin >> v >> w >> a;
weight[w].pub({v, a});
}
for (ll i = 1; i <= s; i++)
{
sort(weight[i].begin(), weight[i].end(), greater <llll>());
for (int j = s; j >= 1; j--)
{
int l = 0;
curval = curnum = 0;
for (ll k = 1; i * k <= j && l <= sz(weight[i]); k++)
{
if (k > curnum)
{
l++;
if (l > sz(weight[i])) break;
curnum += weight[i][l - 1].se;
}
curval += weight[i][l - 1].fi;
dp[j] = max(dp[j], dp[j - i * k] + curval);
//cout << i << sp << j << sp << k << sp << dp[j] << el;
}
ans = max(ans, dp[j]);
}
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(0);
Solve();
return 0;
}
//coded by icyalmond
# | 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... |