2982021-08-20 18:17:22Babják PéterBefektetéscpp11Runtime error 0/4039ms63652 KiB
#include <bits/stdc++.h>
#define N 4010
using namespace std;
struct d
{
	int a,e,t;	
};
struct cmp
{
	bool operator()(const d &p, const d &q)
	{
		return p.t<q.t;
	}	
};
int dp[N][2];
vector<int>atdp[N];
signed main()
{
	int n,k;
	cin>>n>>k;
	vector<d>h(n);
	for(int i=0;i<N;i++)atdp[i].resize(N);
	for(int i=0;i<n;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		h[i].a=a;
		h[i].e=b;
		h[i].t=c;
	}
	sort(h.begin(),h.end(),cmp());
	for(int i=1;i<=k;i++)
	{
		int z;
		for(int j=1;j<=n;j++)
		{
			z=i-h[j-1].a;
			if(z>=0) atdp[i][j]=max(atdp[i][j-1],atdp[z][j-1]+h[j-1].e);
			else atdp[i][j]=atdp[i][j-1];
			
			
			
			bool b=j&1;
			z=i-h[j-1].a-h[j-1].t;
			if(z>=0) dp[i][b]=max(dp[i][!b],atdp[z][j-1]+h[j-1].e);
			else dp[i][b]=dp[i][!b];
		}
	}

	cout<<dp[k][n&1];
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Runtime error0/029ms63324 KiB
2Runtime error0/028ms63380 KiB
3Runtime error0/228ms63444 KiB
4Runtime error0/228ms63396 KiB
5Runtime error0/128ms63452 KiB
6Runtime error0/230ms63196 KiB
7Runtime error0/229ms63200 KiB
8Runtime error0/228ms63204 KiB
9Runtime error0/228ms63212 KiB
10Runtime error0/237ms63208 KiB
11Runtime error0/328ms63220 KiB
12Runtime error0/328ms63240 KiB
13Runtime error0/329ms63236 KiB
14Runtime error0/328ms63276 KiB
15Runtime error0/328ms63288 KiB
16Runtime error0/439ms63312 KiB
17Runtime error0/128ms63580 KiB
18Runtime error0/128ms63600 KiB
19Runtime error0/128ms63616 KiB
20Runtime error0/128ms63632 KiB
21Runtime error0/128ms63644 KiB
22Runtime error0/129ms63652 KiB