2952021-08-20 17:15:45Babják PéterBefektetéscpp11Runtime error 0/402ms1232 KiB
#include <bits/stdc++.h>
#define N 4010
#define int long long
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][N];
int atdp[N][N];
signed main()
{
	int n,k;
	cin>>n>>k;
	vector<d>h(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];
		}
	}
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=n;j++)
		{
			
			int z=i-h[j-1].a-h[j-1].t;
			
			if(z>=0) dp[i][j]=max(dp[i][j-1],atdp[z][j-1]+h[j-1].e);
			else dp[i][j]=dp[i][j-1];
		}
	}
	
	cout<<dp[k][n];
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Runtime error0/02ms1012 KiB
2Runtime error0/01ms1092 KiB
3Runtime error0/21ms1144 KiB
4Runtime error0/21ms1228 KiB
5Runtime error0/11ms1104 KiB
6Runtime error0/21ms1228 KiB
7Runtime error0/21ms1168 KiB
8Runtime error0/21ms1164 KiB
9Runtime error0/21ms1228 KiB
10Runtime error0/21ms1104 KiB
11Runtime error0/31ms1160 KiB
12Runtime error0/31ms1228 KiB
13Runtime error0/31ms1164 KiB
14Runtime error0/31ms1168 KiB
15Runtime error0/31ms1228 KiB
16Runtime error0/41ms1228 KiB
17Runtime error0/11ms1164 KiB
18Runtime error0/11ms1228 KiB
19Runtime error0/11ms1228 KiB
20Runtime error0/11ms1232 KiB
21Runtime error0/11ms1164 KiB
22Runtime error0/11ms1164 KiB