QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534066#5496. 荷马史诗ancienta100 ✓45ms5336kbC++201.1kb2024-08-26 20:13:562024-08-26 20:13:56

Judging History

This is the latest submission verdict.

  • [2024-08-26 20:13:56]
  • Judged
  • Verdict: 100
  • Time: 45ms
  • Memory: 5336kb
  • [2024-08-26 20:13:56]
  • Submitted

answer

#include <iostream>
#include <queue>
using namespace std;
#define LL long long
LL n, k;
LL w;
class node
{
public:
    LL w;
    LL depth;
};
class compare
{
public:
    bool operator()(node a, node b)
    {
        if (a.w == b.w)
        {
            return a.depth > b.depth;
        }
        return a.w > b.w;
    }
};
int main()
{
    priority_queue<node, vector<node>, compare> pq;
    LL len = 0ll;
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
    {
        cin >> w;
        pq.push({w, 0});
    }
    for (int i = 0; i < (n - 1) % (k - 1); ++i)
    {
        pq.push({0, -1000000});
    }
    while (pq.size() > 1)
    {
        LL max_depth = -1000000;
        LL tot_w = 0ll;
        for (int i = 0; i < k; ++i)
        {
            node a = pq.top();
            tot_w += a.w;
            max_depth = max(max_depth, a.depth);
            pq.pop();
        }
        len += tot_w;
        max_depth ++;
        pq.push({tot_w, max_depth});
    }
    node a = pq.top();
    cout << len << endl;
    cout << a.depth << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 3620kb

input:

3 2
1
2
3

output:

9
2

result:

ok Correct Answer.

Test #2:

score: 10
Accepted
time: 0ms
memory: 3504kb

input:

5 2
1
2
1
2
5

output:

23
3

result:

ok Correct Answer.

Test #3:

score: 10
Accepted
time: 0ms
memory: 3804kb

input:

16 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

output:

64
4

result:

ok Correct Answer.

Test #4:

score: 10
Accepted
time: 1ms
memory: 3760kb

input:

1000 2
14595703315
80534380831
17288617047
96364054164
13321445830
86893249112
12443001034
2089068053
30160327449
49676839674
47500435992
33530823897
66417974267
13354465827
58802380258
45331220873
93243099169
60803057858
26327253943
17645598249
50645366634
20814687160
14386178173
62924445593
920727...

output:

481277278083488
19

result:

ok Correct Answer.

Test #5:

score: 10
Accepted
time: 0ms
memory: 3760kb

input:

1000 2
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773123072
58773...

output:

561894565817529
35

result:

ok Correct Answer.

Test #6:

score: 10
Accepted
time: 42ms
memory: 5216kb

input:

100000 2
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
19591041024
195...

output:

32682683660540307
42

result:

ok Correct Answer.

Test #7:

score: 10
Accepted
time: 26ms
memory: 5336kb

input:

100000 2
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
...

output:

55074624
17

result:

ok Correct Answer.

Test #8:

score: 10
Accepted
time: 45ms
memory: 5216kb

input:

100000 2
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
78364164096
783...

output:

130726502977300066
44

result:

ok Correct Answer.

Test #9:

score: 10
Accepted
time: 0ms
memory: 3728kb

input:

7 3
1
1
2
1
2
2
2

output:

20
2

result:

ok Correct Answer.

Test #10:

score: 10
Accepted
time: 0ms
memory: 3804kb

input:

16 3
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98

output:

4214
3

result:

ok Correct Answer.

Extra Test:

score: 0
Extra Test Passed