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 ll long long
#define endl "\n"
int n, m;
vector<vector<pair<int, int> > > a;
ll dp[20005];
vector<pair<int, int> > c;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> m >> n;
a.assign(m + 1, {});
for (int i = 1; i <= n; i++)
{
int v, w, k;
cin >> v >> w >> k;
a[w].push_back({v, k});
}
for (int i = 1; i <= n; i++)
{
sort(a[i].begin(), a[i].end(), greater<pair<int,int> >());
}
for (int i = 1; i <= m; i++)
{
int dem = m / i;
for (auto [v, k] : a[i])
{
if (dem == 0) break;
while (k != 0 && dem != 0)
{
c.push_back({i, v});
k--;
dem--;
}
}
}
// for (auto [i, v] : c)
// {
// cout << i << " ";
// }
// cout << endl;
for (auto [i, v] : c)
{
for (int j = m; j >= i; j--)
{
if (dp[j - i] != 0 || j == i) dp[j] = max(dp[j], dp[j - i] + v);
}
}
cout << *max_element(dp + 1, dp + m + 1);
}
# | 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... |