QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620738#3998. The ProfiteerpurplevineWA 456ms6428kbC++141.7kb2024-10-07 20:54:272024-10-07 20:54:27

Judging History

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

  • [2024-10-07 20:54:27]
  • 评测
  • 测评结果:WA
  • 用时:456ms
  • 内存:6428kb
  • [2024-10-07 20:54:27]
  • 提交

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++) 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 < x; 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++) 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: 100
Accepted
time: 0ms
memory: 3784kb

input:

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

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

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

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

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

output:

7

result:

ok single line: '7'

Test #4:

score: 0
Accepted
time: 438ms
memory: 6256kb

input:

200000 50 23333
2620 5 21
8192 17 34
6713 38 46
6687 13 42
390 9 13
4192 7 37
7898 17 21
1471 16 45
3579 22 40
9628 8 23
7164 28 45
3669 14 31
5549 29 35
4670 30 39
5811 15 20
4162 18 29
7590 29 41
7786 23 35
383 9 40
5576 39 46
5586 4 9
1110 14 33
8568 4 6
8548 39 42
9133 10 42
6679 22 39
8353 33 3...

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 431ms
memory: 6348kb

input:

200000 50 233332
8019 18 20
3111 27 40
2015 16 47
6491 17 18
1224 30 38
428 23 34
7521 4 41
7252 6 33
4121 32 45
4230 18 35
1605 21 42
9489 17 25
3704 35 45
6202 8 22
6493 1 5
3041 14 46
4509 23 43
9646 11 48
5294 19 27
3562 19 40
9408 30 47
1751 21 29
4053 4 27
5596 32 49
8609 13 29
1686 4 31
3588 ...

output:

17523021

result:

ok single line: '17523021'

Test #6:

score: 0
Accepted
time: 322ms
memory: 6296kb

input:

200000 50 2333331
7420 30 44
8652 22 28
5418 8 21
9825 3 8
4257 21 40
9962 6 16
3370 18 41
2192 37 41
231 8 18
7764 3 41
3455 9 18
1159 8 46
9775 9 42
4400 21 43
4593 10 22
712 7 22
2067 21 27
9618 9 35
8008 13 38
114 4 31
4503 39 49
4661 14 41
4837 15 35
1371 12 16
9568 21 48
8934 16 34
870 4 35
83...

output:

20000100000

result:

ok single line: '20000100000'

Test #7:

score: 0
Accepted
time: 456ms
memory: 6428kb

input:

200000 50 253330
4837 37 46
2436 11 48
2043 24 50
3544 27 40
1499 21 43
9009 36 46
9172 11 17
585 29 44
6379 4 28
6630 25 37
9230 24 35
5736 23 50
4324 34 50
4624 23 47
9933 3 12
577 12 18
4411 24 32
8750 42 48
4808 21 34
3904 7 17
5979 41 48
2838 29 40
8682 25 46
4026 11 19
8371 8 42
4550 6 24
1546...

output:

2513593675

result:

ok single line: '2513593675'

Test #8:

score: 0
Accepted
time: 435ms
memory: 6300kb

input:

200000 50 193334
8521 14 21
3902 5 6
2949 4 41
1034 10 36
6156 16 36
9432 35 37
3752 25 37
9668 5 9
3194 43 45
9849 1 26
1582 6 10
9920 20 50
994 34 50
9510 12 38
4513 18 31
6294 3 48
4949 9 18
2348 10 49
5492 19 46
2265 3 37
67 20 40
8752 1 5
4610 27 41
7344 27 39
7767 16 29
921 7 16
1853 23 44
936...

output:

1432887

result:

ok single line: '1432887'

Test #9:

score: 0
Accepted
time: 324ms
memory: 4736kb

input:

100000 100 304560
2347 27 64
3715 15 62
6005 16 86
9856 21 55
1347 5 89
9403 25 33
3889 36 74
554 18 95
5218 27 72
3282 2 68
4955 48 83
3478 7 36
3917 34 99
2117 24 41
9764 35 52
7991 81 94
8026 55 69
7755 27 44
3568 18 50
1968 36 57
7992 63 67
7760 4 55
6938 4 53
722 89 99
1111 47 66
5995 71 80
510...

output:

6114559

result:

ok single line: '6114559'

Test #10:

score: -100
Wrong Answer
time: 329ms
memory: 4740kb

input:

100000 100 404561
3114 87 96
4983 68 99
4734 9 65
3721 49 79
7965 40 74
4463 33 81
731 7 61
9048 36 50
6891 40 68
4236 2 43
5436 6 45
1643 64 85
6889 5 95
5673 21 42
2119 57 70
2940 14 98
5620 59 67
8567 76 90
7543 81 99
5576 4 51
7281 4 100
2485 55 75
9357 6 45
4345 33 62
2261 7 26
2371 4 44
9758 5...

output:

29507027

result:

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