QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620737#3998. The ProfiteerpurplevineWA 0ms4100kbC++141.7kb2024-10-07 20:53:222024-10-07 20:53:22

Judging History

你现在查看的是最新测评结果

  • [2024-10-07 20:53:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4100kb
  • [2024-10-07 20:53:22]
  • 提交

answer

#include <bits/stdc++.h>

using LL = long long;

struct BP {
  std::vector<int> a;
  int n;
  BP(int n) : n(n), a(n + 1) {}
  void upd(int s, int v) {
    for (int i = n; i >= s; i--)
      a[i] = std::max(a[i], a[i - s] + v);
  }
  LL sum() {
    return std::accumulate(a.begin(), a.end(), 0ll);
  }
};

int main() {
  int n, k, E; scanf("%d %d %d", &n, &k, &E);
  LL kE = 1ll * k * E;
  std::vector<int> v(n), a(n), b(n);
  for (int i = 0; i < n; i++)
    scanf("%d %d %d", &v[i], &a[i], &b[i]);
  BP B(k);
  std::vector<int> pl(n);
  std::function<void(int, int, int, int)> solve = [&](int l, int r, int x, int y) {
    if (l > r || x > y) return;
    int m = l + r >> 1;
    BP P = B;
    for (int i = l; i < m && i < x; i++) B.upd(a[i], v[i]);
    for (int i = m; i < r && i < x; i++) B.upd(b[i], v[i]);
    int L = std::max(m, x), R = y, A = R;
    while (L <= R) {
      int M = L + R >> 1;
      auto cur = B;
      for (int i = L; i <= M; i++) cur.upd(b[i], v[i]);
      for (int i = M + 1; i <= R; i++) cur.upd(a[i], v[i]);
      if (cur.sum() <= kE) {
        for (int i = M; i <= R; i++) B.upd(a[i], v[i]);
        A = M, R = M - 1;
      } else {
        for (int i = L; i <= M; i++) B.upd(b[i], v[i]);
        L = M + 1;
      }
    }
    // printf("%d : %d\n", m, A);
    pl[m] = A, B = P;
    for (int i = m; i <= r; i++) B.upd(b[i], v[i]);
    for (int i = A + 1; i <= y; i++) B.upd(a[i], v[i]);
    solve(l, m - 1, x, A), B = P;
    for (int i = l; i <= m && i < x; i++) B.upd(a[i], v[i]);
    for (int i = std::max(r, x); i < y; i++) B.upd(b[i], v[i]);
    solve(m + 1, r, A, y); 
  };
  solve(0, n - 1, 0, n);
  long long ans = 0;
  for (int i = 0; i < n; i++)
    ans += n - pl[i];
  printf("%lld\n", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4100kb

input:

4 5 3
3 2 4
1 2 3
2 1 2
3 1 3

output:

3

result:

wrong answer 1st lines differ - expected: '1', found: '3'