| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 9 초 | 2048 MB | 41 | 11 | 9 | 23.077% |
A research facility operates two buildings, Left Lab and Right Lab, connected by a single secure corridor. At the beginning, all selected employees are standing in the Left Lab.
To see how the strategy affects the total time, consider four employees whose individual traversal times $\{1, 2, 5, 10\}$. One possible strategy is as follows. If $(1, 2)$ traverse first (taking $2$ minutes), then $(1)$ returns with the badge ($1$ minute), then $(1, 5)$ traverse ($5$ minutes), $(1)$ returns ($1$ minute), and finally $(1, 10)$ traverse ($10$ minutes), the total time is $19$ minutes. However, there is another (better) strategy; if $(1, 2)$ traverse first ($2$ minutes), $(1)$ returns ($1$ minute), then $(5, 10)$ traverse together ($10$ minutes), $(2)$ returns ($2$ minutes), and finally $(1, 2)$ traverse again ($2$ minutes), the total time becomes $17$ minutes, which yields a smaller total traversal time than the first. For convenience, the two crossing sequences are summarized in Tables 1 and 2 below.
Table 1. Sequence A (Total $19$ min)
| Step | Action | Left Lab (after) | Right Lab (after) | Duration (min) | Elapsed (min) |
|---|---|---|---|---|---|
| $0$ | - | $\{1,2,5,10\}$ | $∅$ | - | - |
| $1$ | Cross $(1, 2)$ | $\{5,10\}$ | $\{1,2\}$ | $2$ | $2$ |
| $2$ | Return $(1)$ | $\{1,5,10\}$ | $\{2\}$ | $1$ | $3$ |
| $3$ | Cross $(1, 5)$ | $\{10\}$ | $\{1,2,5\}$ | $5$ | $8$ |
| $4$ | Return $(1)$ | $\{1,10\}$ | $\{2,5\}$ | $1$ | $9$ |
| $5$ | Cross $(1, 10)$ | $∅$ | $\{1,2,5,10\}$ | $10$ | $19$ |
Table 2. Sequence B (Total $17$ min)
| Step | Action | Left Lab (after) | Right Lab (after) | Duration (min) | Elapsed (min) |
|---|---|---|---|---|---|
| $0$ | - | $\{1,2,5,10\}$ | $∅$ | - | - |
| $1$ | Cross $(1, 2)$ | $\{5,10\}$ | $\{1,2\}$ | $2$ | $2$ |
| $2$ | Return $(1)$ | $\{1,5,10\}$ | $\{2\}$ | $1$ | $3$ |
| $3$ | Cross $(5, 10)$ | $\{1\}$ | $\{2,5,10\}$ | $10$ | $13$ |
| $4$ | Return $(2)$ | $\{1,2\}$ | $\{5,10\}$ | $2$ | $15$ |
| $5$ | Cross $(1,2)$ | $∅$ | $\{1,2,5,10\}$ | $2$ | $17$ |
You are given $n$ employees. Employee $i$ needs $T_i$ minutes to traverse the corridor. You are also given $q$ queries. Each query is specified by:
For each query, consider all employees whose indices lie in $[x, y]$ and whose traversal times lie in $[a, b]$. Among these employees, select the $K$ employees who have the smallest individual traversal times. If fewer than $K$ such employees exist, select all of them. These selected employees all start in the Left Lab with the single badge. Under the rules described above, you should compute the minimum total traversal time required for all selected employees to reach the Right Lab. If no employee is selected, the answer should be zero.
Given $n$ employees with traversal times $T_1, \cdots , T_n$ and $q$ queries of the form $(x, y, a, b, K)$, write a program that processes the queries and outputs, for each query, the minimum total traversal time for the selected employees to reach the Right Lab.
Your program is to read from standard input. The input starts with a line containing two integers $n$ and $q$ ($1 ≤ n, q ≤ 100\,000$), where $n$ is the number of employees and $q$ is the number of queries. Employees are numbered from $1$ to $n$. The second line contains $n$ integers $T_1, \cdots , T_n$ ($1 ≤ T_i ≤ 10^9$), where $T_i$ is the traversal time of employee $i$ ($1 ≤ i ≤ n$). Each of the following $q$ lines contains five integers $x, y, a, b, K$ described above, where $1 ≤ x ≤ y ≤ n$; $1 ≤ a ≤ b ≤ 10^9$; $1 ≤ K ≤ n$.
Your program is to write to standard output. For each query, print a single line containing the minimum total traversal time for the selected employees to move from the Left Lab to the Right Lab. If no employee is selected, output $0$.
3 3 1 2 3 1 3 1 3 3 1 3 1 3 2 1 3 4 5 1
6 2 0
4 4 5 1 10 2 1 4 1 10 4 1 4 2 10 2 1 4 2 10 4 1 3 1 13 3
17 5 17 16
ICPC > Regionals > Asia Pacific > Korea > 2025 ICPC Asia Seoul Regional B번