比赛 2025暑假集训第一场 评测结果 AAAAAAWWAAAWAWWWWWWW
题目名称 免费的馅饼(加强版) 最终得分 50
用户昵称 LikableP 运行时间 0.150 s
代码语言 C++ 内存使用 1.53 MiB
提交时间 2025-06-25 10:57:46
显示代码纯文本
#include <algorithm>
#include <cstdio>
#define isdigit(ch) ((ch) >= '0' && (ch) <= '9')
typedef long long ll;

namespace IO {
template <typename T>
T read() {
  T res = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    res = (res << 3) + (res << 1) + (ch ^ 48);
  return res * f;
}

template <typename T>
void write(T x, char ed = '\n') {
  if (x < 0)
    x = -x, putchar('-');
  static int sta[sizeof(T) << 2], top = 0;
  do {
    sta[++top] = x % 10;
    x /= 10;
  } while (x);
  while (top) {
    putchar(sta[top--] ^ 48);
  }
  putchar(ed);
}
} // namespace IO
using namespace IO;

const int MAXN = 1e5 + 10;

struct ITEM {
  int time, block, w;
} a[MAXN];

int n;
int del;
ll ans;

int main() {
  freopen("free.in", "r", stdin);
  freopen("free.out", "w", stdout);
  read<int>(), n = read<int>();
  for (int i = 1; i <= n; ++i) {
    a[i].time = read<int>(), a[i].block = read<int>(), a[i].w = read<int>();
  }

  ::std::sort(a + 1, a + n + 1, [](ITEM x, ITEM y) {
    return x.time < y.time;
  });
  for (int i = 2; i <= n; ++i) {
    if (a[i].time == a[i - 1].time) {
      if (a[i].block == a[i - 1].block) {
        a[i].w += a[i - 1].w;
      } else {
        a[i].w = ::std::max(a[i].w, a[i - 1].w);
      }
      a[i - 1] = {0x7fffffff, 0, 0};
      del++;
    }
  }
  ::std::sort(a + 1, a + n + 1, [](ITEM x, ITEM y) {
    return x.time < y.time;
  });

  n = n - del;

  int nb = a[1].block, nt = a[1].time;
  ans = a[1].w;
  for (int i = 2; i <= n; ++i) {
    if ((a[i].time - nt) * 2 >= abs(a[i].block - nb)) {
      nb = a[i].block;
      nt = a[i].time;
      ans += a[i].w;
    }
  }

  write(ans);
  return 0;
}