比赛 |
2025暑假集训第一场 |
评测结果 |
AWWWWWWWAAAAAWWWWWTT |
题目名称 |
免费的馅饼(加强版) |
最终得分 |
30 |
用户昵称 |
OTTF |
运行时间 |
5.097 s |
代码语言 |
C++ |
内存使用 |
3.79 MiB |
提交时间 |
2025-06-25 08:41:00 |
显示代码纯文本
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 114514;
struct pancake {
int t;
int p;
int v;
bool operator< (pancake other) {
return t < other.t;
}
};
int n;
int w;
pancake nums[N];
int dp[N];
int res;
void ParseIn () {
freopen ("free.in", "r" ,stdin);
freopen ("free.out", "w", stdout);
cin >> w >> n;
for (int i = 1; i <= n; i++) {
cin >> nums[i].t >> nums[i].p >> nums[i].v;
}
sort (nums + 1, nums + 1 + n);
}
void Core () {
for (int i = 1; i <= n; i++) {
dp[i] = nums[i].v;
for (int j = 1; j < i; j++) {
if (nums[i].t - nums[j].t >= abs (nums[i].p - nums[j].p)) {
dp[i] = max (dp[i], dp[j] + nums[i].v);
}
}
res = max (res, dp[i]);
}
}
void CWriteOut () {
cout << res << endl;
}
int main () {
ParseIn ();
Core ();
CWriteOut ();
return 0;
}