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;
int s,n,dp[2005][2005];
vector<pair<int,int>> v[2005];
signed main()
{
cin>>s>>n;
for (int i =1 ; i<= n; i++)
{
int x,y,z;
cin>>x>>y>>z;
v[y].push_back({x,z});
}
for (int i = 1; i <= s; i++)
{
sort(v[i].begin(),v[i].end());
}
for (int i = 1; i <= s; i++)
{
int val=0;
for (int j = 0; j <= s; j+=i)
{
for (int k = j; k <= s; k++)
{
dp[i][k]=max(dp[i][k],dp[i-1][k-j]+val);
}
if (v[i].empty()) break;
val+=v[i].back().first;
v[i].back().second--;
if (v[i].back().second==0) v[i].pop_back();
}
}
/* for (int i = 1; i <= s; i++)
{
for (int j = 1; j <= s; j++)
{
cout<<dp[i][j]<<' ';
}
cout<<endl;
}*/
cout<<dp[s][s];
}
# | 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... |