시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
180 초 (추가 시간 없음) | 1024 MB | 5 | 2 | 2 | 40.000% |
Supervin is teaching N classes, which are numbered from 1 to N. After giving his most recent exam, he noticed that in each of his classes, the test scores of his students form a sequence of consecutive integers. Therefore, Supervin can summarize the scores for the i-th class as two integers Li and Ri. This means that the i-th class has Ri - Li + 1 students, and for each x (Li ≤ x ≤ Ri), there is exactly one student with score x.
Supervin would like to combine the scores from the students from all of his classes and sort the scores in non-increasing order. He has Q questions (numbered from 1 to Q) about this list; for the i-th question, he wants to know what the Ki-th highest score is. (If Ki is greater than the number of students, then the answer for the i-th question is 0.)
Can you help Supervin answer all of his questions? Since there may be many answers, instead of outputting all of them, output proof that you have answered them: the sum of (Si × i) for all 1 ≤ i ≤ Q, where Si is the answer to the i-th question.
The first line of the input gives the number of test cases, T. T test cases follow. Each test case contains four lines. The first line contains two integers N and Q as described above. The next three lines each contain six integers in the following format, respectively:
These values are used to generate Li, Ri, and Ki as follows:
We define:
We also define:
For each test case, output one line containing Case #x: y
, where x
is the test case number (starting from 1) and y
is the sum of (Si × i) for all 1 ≤ i ≤ Q, where Si is the answer to the i-th question.
2 5 1 3 1 4 1 5 9 2 7 1 8 2 9 4 8 15 16 23 42 7 1 2 3 4 5 6 31 1 3 4 5 5 17 2 2 1 3 2 100
Case #1: 7 Case #2: 28
In Sample Case #1, the generated arrays X, Y, Z are:
Therefore,
The students' scores for each of the classes are [3, 4], [2, 3, 4, 5, 6, 7, 8], [4, 5, 6, 7, 8], [1, 2, 3], and [7, 8, 9]. This means that the students' scores for all classes combined are [3, 4, 2, 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 1, 2, 3, 7, 8, 9]. If we sort them in non-increasing order, they are [9, 8, 8, 8, 7, 7, 7, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 1]. Therefore, the student with the 5th highest score has score 7. Thus, S = [7] and the answer is 7 × 1 = 7.
2 5 5 3 1 4 1 5 9 2 7 1 8 2 9 4 8 15 16 23 42 1 2 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 2
Case #1: 39 Case #2: 1
In Sample Case #1, every parameter is the same as Sample Case #1 except the value of Q. Therefore, the values of L and R, and the students' scores for all classes combined are still the same as Sample Case #1. However, the queries are now K = [5, 9, 40, 23, 12]. The students with the 5th, 9th, and 12th highest scores have scores of 7, 6, and 4, respectively. Since there are only 20 students, the 23rd and 40th students do not exist. Therefore, S = [7, 6, 0, 0, 4] and the answer is 7 × 1 + 6 × 2 + 0 × 3 + 0 × 4 + 4 × 5 = 7 + 12 + 20 = 39.
In Sample Case #2, the generated arrays X, Y, Z are:
Therefore,
Therefore, there is only one student, and S = [1, 0], so the answer is 1 × 1 + 0 × 2 = 1.
Contest > Google > Kick Start > Google Kick Start 2018 > Round G B번