| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4.5 초 | 768 MB | 130 | 31 | 21 | 19.266% |
There are N mountains lying in a horizontal row, numbered from 0 through N - 1from left to right. The height of the mountain i is Hi (0 ≤ i ≤ N - 1). Exactly one person lives on the top of each mountain.
You are going to hold Q meetings, numbered from 0 through Q - 1. The meeting j (0 ≤ j ≤ Q - 1) will be attended by all the people living on the mountains from Lj to Rj, inclusive (0 ≤ Lj ≤ Rj ≤ N - 1). For this meeting, you must select a mountain x as the meeting place (Lj ≤ x ≤ Rj). The cost of this meeting, based on your selection, is then calculated as follows:
For each meeting, you want to find the minimum possible cost of holding it.
Note that all participants go back to their own mountains after each meeting; so the cost of a meeting is not influenced by the previous meetings.
You should implement the following function:
int64[] minimum_costs(int[] H, int[] L, int[] R)
H: an array of length N, representing the heights of the mountains.L and R: arrays of length Q, representing the range of the participants in the meetings.Let N = 4, H = [2, 4, 3, 5], Q = 2, L = [0, 1], and R = [2, 3].
The grader calls minimum_costs([2, 4, 3, 5], [0, 1], [2, 3]).
The meeting j = 0 has Lj = 0 and Rj = 2, so will be attended by the people living on the mountains 0, 1, and 2. If the mountain 0 is chosen as the meeting place, the cost of the meeting 0 is calculated as follows:
It is impossible to hold the meeting 0 at a lower cost, so the minimum cost of the meeting 0 is 10.
The meeting j = 1 has Lj = 1 and Rj = 3, so will be attended by the people living on the mountains 1, 2, and 3. If the mountain 2 is chosen as the meeting place, the cost of the meeting 1 is calculated as follows:
It is impossible to hold the meeting 1 at a lower cost, so the minimum cost of the meeting 1 is 12.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 4 | N ≤ 3,000, Q ≤ 10 |
| 2 | 15 | N ≤ 5,000, Q ≤ 5,000 |
| 3 | 17 | N ≤ 100,000, Q ≤ 100,000, Hi ≤ 2 (0 ≤ i ≤ N - 1) |
| 4 | 24 | N ≤ 100,000, Q ≤ 100,000, Hi ≤ 20 (0 ≤ i ≤ N - 1) |
| 5 | 40 | No additional constraints |
The sample grader reads the input in the following format:
The sample grader prints the return value of minimum_costs in the following format:
Olympiad > International Olympiad in Informatics > IOI 2018 > Day 2 6번
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)