输入
4 16 3
1 1 1
1 3 2
1 4 4
1 6 8
输出
10
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b;i ++ )
#define fd(i,a,b) for(int i=a;i>=b;i -- )
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long LL;
typedef vector<vector<LL>> VVL;
typedef pair<int,int> PII;
const int N = 1e5+ 10,M = N *4,INF = 0x3f3f3f3f ;
int n,m,k;
int day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int s[13];
PII q[N];
int h[N],e[M],w[M],idx,ne[M],d[N];
bool st[N];
void add(int a,int b,int c)
{
e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;
}
int spfa(int now)
{
ms(d,-0x3f);
ms(st,0);
d[now] =0;
priority_queue<PII> q;
q.push({0,now});
while(q.size())
{
auto t = q.top();q.pop();
st[t.y]=0;
for(int i=h[t.y];~i;i=ne[i])
{
int j = e[i];
if(d[j] < d[t.y] + w[i])
{
d[j] = d[t.y] + w[i];
if(!st[j])
{
st[j] = 1;
q.push({d[j],j});
}
}
}
}
int ans =0 ;
fu(i,0,n-1)ans =max(ans,d[i]);
return ans;
}
inline void solve()
{
// cin >> n>> m>> k;
scanf("%d%d%d",&n,&m,&k);
fu(i,1,12) s[i] = s[i-1] + day[i];
fu(i,0,n-1)
{
int a,b,c;
// cin >> a>>b >> c;
scanf("%d%d%d",&a,&b,&c);
int d=s[a-1] + b;
q[i] = {d,c};
}
sort(q,q+n);
ms(h,-1);
fu(i,0,n-1)
fu(j,i+1,n-1)
{
if(q[j].x- q[i].x>= k)
add(i,j,min(q[j].y,m));
}
int res =0;
fu(i,0,n-1)
res = max(res,q[i].y + spfa(i));
cout << res <<endl;
}
signed main()
{
// freopen("1.txt","w",stdout);
// ios
int t=1;
// cin>>t;
int now = 1;
while(t -- )
{
// cout<<"Case ";
// cout<<"Scenario #";
// cout<< now ++ <<": ";
// cout<< now ++ <<": \n";
solve();
}
return 0;
}