QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#320956#5441. Quartz CollectionduckindogWA 2ms6044kbC++141.4kb2024-02-04 00:45:352024-02-04 00:45:36

Judging History

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

  • [2024-02-04 00:45:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6044kb
  • [2024-02-04 00:45:35]
  • 提交

answer

//from duckindog wth depression
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int N = 1e5 + 10;

int n, m;
struct quartz {
  int a, b, t;
  quartz() : a(0), b(0), t(0) {}
  quartz(int a, int b, int t) : a(a), b(b), t(t) {}
} x[N];

int d[N];
int cal() {
  sort(x + 1, x + n + 1, [&](const auto&x, const auto& y) {
    return make_pair(x.a - x.b, x.a) < make_pair(y.a - y.b, y.a);
  });
  for (int i = 1; i <= n; ++i) d[i] = x[i].a - x[i].b;
  int answer = d[1];
  for (int i = 1; i <= n; ++i) answer += x[i].b;
  bool player = 0;
  int it = 2;
  while (d[it + 1] <= 0 && it < n) {
    if (player) answer += d[it] + d[it + 1];
    player = 1 - player;
    it += 2;
  }

  if (it == n) {
    if (d[it] <= 0)
      return answer + d[it] * player;

    return answer + d[it] * (!player);
  }
  it += 1 + player;
  while (it <= n) {
    answer += d[it];
    it += 2;
    player = 1 - player;
  }
  return answer;
}

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);

  if (fopen("duck.inp", "r")) {
    freopen("duck.inp", "r", stdin);
    freopen("duck.out", "w", stdout);
  }

  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    int a, b; cin >> a >> b;
    x[i] = {a, b, i};
  }
  cout << cal() << "\n";
  for (int i = 1; i <= m; ++i) {
    int t, a, b; cin >> t >> a >> b;
    for (int j = 1; j <= n; ++j) if (x[j].t == t) x[j] = {a, b, t};
    cout << cal() << "\n";
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5952kb

input:

4 5
2 4
5 7
1 7
2 1
4 5 2
1 6 2
4 4 3
2 1 3
3 6 6

output:

13
14
15
14
10
13

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 2ms
memory: 6044kb

input:

1 1
1 1
1 1 1

output:

1
1

result:

ok 2 number(s): "1 1"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5924kb

input:

100 100
6 7
100 8
5 61
5 75
59 65
51 47
83 37
34 54
87 46
4 26
21 87
12 97
86 68
60 11
62 76
14 83
29 31
91 62
57 80
47 75
85 97
62 77
91 86
14 25
48 77
83 65
39 61
78 77
45 46
90 74
100 91
86 98
55 5
84 42
91 69
100 4
74 98
60 37
75 44
41 12
15 34
36 1
99 16
7 87
36 26
79 42
41 84
17 98
72 16
38 55...

output:

5109
5103
5101
5007
4975
4993
4950
4928
4974
4930
4999
4966
4936
4925
4898
4864
4837
4787
4793
4827
4730
4763
4715
4668
4597
4671
4708
4687
4677
4685
4714
4733
4779
4701
4660
4631
4628
4682
4743
4777
4821
4821
4800
4805
4775
4744
4672
4687
4746
4699
4661
4543
4573
4609
4605
4585
4532
4520
4489
4550
...

result:

wrong answer 2nd numbers differ - expected: '5065', found: '5103'