#P14668. [ICPC 2025 Seoul R] Badge Relay
[ICPC 2025 Seoul R] Badge Relay
题目描述
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.
- The corridor can hold at most two people at a time.
- There is exactly one security badge, and every traversal of the corridor (whether by one person or two together) must be accompanied by the badge.
- If two people travel together, they must walk side by side, and the traversal time is equal to the slower person's time.
- If there are still employees remaining in the Left Lab after a traversal to the Right Lab, then someone in Right Lab must bring the badge back to the Left Lab before the next traversal from the Left Lab to the Right Lab can begin.
To see how the strategy affects the total time, consider four employees whose individual traversal times . One possible strategy is as follows. If traverse first (taking 2 minutes), then returns with the badge (1 minute), then traverse (5 minutes), returns (1 minute), and finally traverse (10 minutes), the total time is minutes. However, there is another (better) strategy; if traverse first (2 minutes), returns (1 minute), then traverse together (10 minutes), returns (2 minutes), and finally traverse again (2 minutes), the total time becomes 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.
:::align{center} Table 1. Sequence A (Total 19 min) :::
| Step | Action | Left Lab (after) | Right Lab (after) | Duration (min) | Elapsed (min) |
|---|---|---|---|---|---|
| 0 | - | - | |||
| 1 | Cross | ||||
| 2 | Return | ||||
| 3 | Cross | ||||
| 4 | Return | ||||
| 5 | Cross | ||||
:::align{center} Table 2. Sequence B (Total 17 min) :::
| Step | Action | Left Lab (after) | Right Lab (after) | Duration (min) | Elapsed (min) |
|---|---|---|---|---|---|
| 0 | - | - | |||
| 1 | Cross | ||||
| 2 | Return | ||||
| 3 | Cross | ||||
| 4 | Return | ||||
| 5 | Cross | ||||
You are given employees. Employee needs minutes to traverse the corridor. You are also given queries. Each query is specified by:
- an index range (inclusive),
- a time range (inclusive), and
- a selection cap (the maximum number of employees you may select).
For each query, consider all employees whose indices lie in and whose traversal times lie in . Among these employees, select the employees who have the smallest individual traversal times. If fewer than 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 employees with traversal times and queries of the form , write a program that processes the queries and outputs, for each query, the minimum total traversal time for the selected employees to move from the Left Lab to the Right Lab.
输入格式
Your program is to read from standard input. The input starts with a line containing two integers and (), where is the number of employees and is the number of queries. Employees are numbered from 1 to . The second line contains integers (), where is the traversal time of employee (). Each of the following lines contains five integers described above, where ; ; .
输出格式
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
提示
翻译由 DeepSeek V3 完成