比赛 2025暑假集训第一场 评测结果 AAAAAAWWAAAWAWWWWWWW
题目名称 免费的馅饼(加强版) 最终得分 50
用户昵称 Hollow07 运行时间 0.407 s
代码语言 C++ 内存使用 3.96 MiB
提交时间 2025-06-25 11:47:49
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct node{
    ll t,p,v;
}z[110000],l;

ll ch[11000000];
ll w,n,ans,mm,x,y;
ll dp[110000];

bool cmp(node a,node b){
    if (a.t==b.t) return a.v>b.v;
    else return a.t<b.t;
}

//void chh(ll zb,ll num,ll time){
//    if (time>mm)return;
//    if (zb<=0)return;
//    if (zb>w)return;
//    if(ch[zb]!=0){
//        if (z[ch[zb]].t==time){
//            num+=z[ch[zb]].v;
//        }
//    }
//    ans=max(ans,num);
//    chh(zb-2,num,time+1);
//    chh(zb-1,num,time+1);
//    chh(zb,num,time+1);
//    chh(zb+1,num,time+1);
//    chh(zb+2,num,time+1);
//}

int main(){
    freopen("free.in","r",stdin);
    freopen("free.out","w",stdout);
    cin>>w>>n;
    for (int i=1;i<=n;i++){
        cin>>z[i].t>>z[i].p>>z[i].v;
    }
    sort(z+1,z+n+1,cmp);
    l=z[1];
    ans=z[1].v;
	for(int i=2;i<=n;i++){
		if(2*(z[i].t-l.t)>=abs(z[i].p-l.p)){
			ans+=z[i].v;
			l=z[i];
		}
	}
	cout<<ans<<endl;
    fclose(stdin);
    fclose(stdout);
    return 0;
}