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 ll int
#define ft first
#define sc second
using namespace std;
const int N=1e5+10;
ll s,n,dp[N];
vector <pair<int,int>> v[N];
vector <int>pre[N];
int cal(int i,int j)
{
return pre[i][j-1];
}
void lulu_solution()
{
cin >> s >> n;
for (int i=1;i<=s;i++) dp[i]=-1044266559;
dp[0]=0;
int res=dp[1];
for (ll i=1;i<=n;i++)
{
int val,w,k;
cin >> val >>w >> k;
v[w].push_back({val,k});
}
for (ll i=1;i<=s;i++)
{
sort(v[i].begin(),v[i].end(),greater<pair<ll,ll>>());
int cur=0;
int cnt=s/i;
for (int j=0;j<v[i].size();j++)
{
while (v[i][j].sc&&cnt)
{
cur+=v[i][j].ft;
--cnt;
--v[i][j].sc;
pre[i].push_back(cur);
}
}
}
for (ll i=1; i<=s; i++)
{
for (int j=s;j>=i;j--)
{
for (int k=j-i;(k>=0&&(j-k)/i<=(int) pre[i].size());k-=i) dp[j]=max(dp[j],dp[k]+cal(i,(j-k)/i));
}
}
cout << *max_element(dp,dp+s+1);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
lulu_solution();
}
Compilation message (stderr)
knapsack.cpp: In function 'void lulu_solution()':
knapsack.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int j=0;j<v[i].size();j++)
| ~^~~~~~~~~~~~
knapsack.cpp:19:9: warning: unused variable 'res' [-Wunused-variable]
19 | int res=dp[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... |