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 int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 2005;
const int mod7 = 1e9+7;
const long long inf = 1e18;
bool cmp(pii p1, pii p2)
{
if(p1.fi == p2.fi)return p1.sc<p2.sc;
return p1.fi>p2.fi;
}
signed main()
{
ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--)
{
int s,n;
cin >> s >> n;
vector<vector<pii>> svi(MAXN);
for(int i=0; i<n; i++)
{
int v,w,k;cin >> v >> w >> k;
svi[w].pb(mp(v,k));
}
vector<pii> niz;
for(int i=1; i<=s; i++)
{
sort(all(svi[i]), cmp);
int cnt = s/i;
for(auto x: svi[i])
{
if(cnt<=0)break;
for(int j=0; j<x.sc; j++)
{
if(cnt<=0)break;
cnt--;
niz.pb(mp(i, x.fi));
}
}
}
int m = niz.size();
vector<vector<int>> dp(2, vector<int>(MAXN));
for(int i=0; i<m; i++)
{
for(int j = 1; j<=s; j++)
{
if(niz[i].fi <= j)dp[1][j] = max({dp[0][j], dp[0][j-niz[i].fi] + niz[i].sc});
else dp[1][j] =dp[0][j];
}
dp[0] = dp[1];
}
cout << dp[1][s] << endl;
}
}
# | 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... |