比赛 |
2025暑假集训第一场 |
评测结果 |
AAAAAAAAAAAAAEAAAEEE |
题目名称 |
免费的馅饼(加强版) |
最终得分 |
80 |
用户昵称 |
wdsjl |
运行时间 |
0.641 s |
代码语言 |
C++ |
内存使用 |
3.77 MiB |
提交时间 |
2025-06-25 11:15:25 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
int w, n, dp[N], mt;
struct str {
int t, p, v;
} a[N];
bool cmp(str x, str y) { return x.t < y.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++) {
dp[i] = a[i].v;
for(int j = 1; j < i; j++) {
if(abs(a[i].t - a[j].t) * 2 >= abs(a[i].p - a[j].p))
dp[i] = max(dp[i], dp[j] + a[i].v);
}
}
int ans = 0;
for(int i = 1; i <= n; i++) ans = max(ans, dp[i]);
printf("%d", ans);
return 0;
}