比赛 |
2025暑假集训第一场 |
评测结果 |
AWWWWWWWAAAAAWWWWWTT |
题目名称 |
免费的馅饼(加强版) |
最终得分 |
30 |
用户昵称 |
左清源 |
运行时间 |
5.071 s |
代码语言 |
C++ |
内存使用 |
3.97 MiB |
提交时间 |
2025-06-25 12:57:20 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int N=1e5+10;
int n,w,f[N],ans;
struct node{int p,t,v;}a[N];
bool cmp(node a,node b){
return a.t<b.t;
}
int main(){
freopen("free.in","r",stdin);
freopen("free.out","w",stdout);
scanf("%d %d",&w,&n);
for(int i=1;i<=n;i++)scanf("%d %d %d",&a[i].t,&a[i].p,&a[i].v);
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++){
f[i]=a[i].v;
for(int j=1;j<i;j++){
if(a[i].t-a[j].t>=abs(a[i].p-a[j].p))f[i]=max(f[i],f[j]+a[i].v);
}
ans=max(ans,f[i]);
}
printf("%d\n",ans);
return 0;
}
/*
10 5
1 7 545
1 2 388
6 9 125
7 1 148
7 5 573
*/