比赛 |
2025暑假集训第一场 |
评测结果 |
AAAAAAAAAAAAAAAAAATT |
题目名称 |
免费的馅饼(加强版) |
最终得分 |
90 |
用户昵称 |
淮淮清子 |
运行时间 |
5.083 s |
代码语言 |
C++ |
内存使用 |
3.85 MiB |
提交时间 |
2025-06-25 11:19:26 |
显示代码纯文本
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 100005;
int w,n;
struct node{
int t,p,v;
}b[MAXN];
long long dp[MAXN],ans = 0;
bool cmp(node x,node y){
return x.t < y.t;
}
int main(){
freopen("free.in","r",stdin);
freopen("free.out","w",stdout);
cin.tie(0) -> ios::sync_with_stdio(0);
cin >> w >> n;
for(int i = 1;i <= n;i ++){
cin >> b[i].t >> b[i].p >> b[i].v;
}
sort(b + 1,b + n + 1,cmp);
for(int i = 1;i <= n;i ++){
dp[i] = b[i].v;
for(int j = 1;j < i;j ++){
if(2 * abs(b[i].t - b[j].t) >= abs(b[i].p - b[j].p)){
dp[i] = max(dp[i],dp[j] + b[i].v);
}
}
}
for(int i = 1;i <= n;i ++){
ans = max(ans,dp[i]);
}
cout << ans << '\n';
return 0;
}