QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227208#7342. Waiter's ProblemLainAC ✓79ms4052kbC++23597b2023-10-27 02:18:442023-10-27 02:18:44

Judging History

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

  • [2023-10-27 02:18:44]
  • 评测
  • 测评结果:AC
  • 用时:79ms
  • 内存:4052kb
  • [2023-10-27 02:18:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int tt;
  cin >> tt;
  while(tt--) {
    int n;
    cin >> n;
    vi a(n);
    int64_t sum = 0;
    for (auto& x : a) cin >> x;
    sort(all(a));
    reverse(all(a));
    rep(i, 0, n) {
      sum += max(a[i] - i, 0);
    }
    cout << sum << '\n';
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

input:

1
6
0 9 9 1 7 5

output:

24

result:

ok 1 number(s): "24"

Test #2:

score: 0
Accepted
time: 79ms
memory: 4052kb

input:

10007
2
6 2
5
2 3 2 10 6
2
5 0
2
1 7
6
2 4 4 2 1 5
8
6 10 1 8 0 10 9 0
3
10 5 5
10
4 9 9 5 5 2 6 7 9 4
1
7
2
0 0
7
9 4 4 6 1 8 2
10
6 6 8 6 4 4 7 2 1 8
9
7 4 9 8 3 0 2 0 10
4
1 4 9 4
2
2 5
3
5 1 3
10
4 1 6 5 3 8 6 3 2 3
10
0 0 2 9 2 1 10 6 8 6
9
2 4 1 4 2 8 5 3 0
2
4 10
9
2 7 9 2 7 3 9 5 2
5
3 5 5 9...

output:

7
16
5
7
10
33
17
30
7
0
21
26
28
14
6
7
19
29
15
13
27
16
15
32
7
21
6
25
9
29
27
13
29
13
22
24
24
13
22
22
6
23
26
5
3
9
41
8
21
30
7
37
40
20
2
14
5
26
25
21
23
15
1
16
4
19
16
7
26
13
11
6
7
41
21
15
27
16
33
33
24
22
23
12
17
18
16
8
30
21
21
15
10
17
29
16
6
22
25
16
1
7
30
28
30
20
18
27
24
...

result:

ok 10007 numbers