Universal Cup Judging System

Universal Cup

时间限制: 1.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓
统计

Panda 是一名船夫,在一條河上撐船。這艘船每次最多只能載一名乘客。

某一天,有 $n$ 個人想要從河的左岸渡到右岸,他們抵達左岸河邊的時間分別為 $a_1, a_2, \ldots, a_n$。另外還有 $m$ 個人想要從右岸渡到左岸,他們抵達右岸河邊的時間分別為 $b_1, b_2, \ldots, b_m$。每位乘客只能在其抵達時間或之後登船。

無論船上是否載有乘客,渡河一次都恰好需要 $k$ 個單位時間。Panda 可以自行選擇船的起始位置(左岸或右岸)。目標是找出一份渡河時間表,使得這 $n + m$ 個人當中最後一人抵達對岸目的地的時間最小化。你還需要幫助 Panda 確定完整的渡河時間表。

輸入格式

第一行包含三個整數 $n, m, k$($1 \le n, m \le 10^5$,$1 \le k \le 10^9$),分別表示從左岸出發的人數、從右岸出發的人數,以及單次渡河所需的時間。

第二行包含 $n$ 個整數 $a_1, a_2, \ldots, a_n$($1 \le a_i \le 10^9$),表示左岸各人的抵達時間。

第三行包含 $m$ 個整數 $b_1, b_2, \ldots, b_m$($1 \le b_i \le 10^9$),表示右岸各人的抵達時間。

輸出格式

第一行應包含一個整數 $T$,代表最後一位乘客抵達目的地的最小可能時間。

接下來的 $n + m$ 行應按時間先後順序描述渡河時間表。第 $i$ 行包含三個整數 $t_i, tp_i, id_i$($0 \le t_i \le T$,$tp_i \in \{0, 1\}$),表示在時刻 $t_i$,來自左岸($tp_i = 0$)或右岸($tp_i = 1$)編號為 $id_i$ 的乘客登船。當 $tp_i = 0$ 時,你必須確保 $1 \le id_i \le n$ 且 $t_i \ge a_{id_i}$;當 $tp_i = 1$ 時,你必須確保 $1 \le id_i \le m$ 且 $t_i \ge b_{id_i}$。此外,你必須確保 $t_1 < t_2 < \cdots < t_{n+m}$ 且 $T = \max_i(t_i + k)$。

對於合法的時間表,這 $n + m$ 個人中的每一個人都必須成功登船並抵達對岸。連續兩次登船時間的間隔必須至少為 $k$,即對於所有 $1 < i \le n + m$ 皆滿足 $t_i - t_{i-1} \ge k$。如果連續兩個人從同一側河岸登船($tp_i = tp_{i-1}$),他們登船時間的間隔必須至少為 $2k$,即 $t_i - t_{i-1} \ge 2k$。

範例

5 5 2
2 1 13 19 11
12 18 19 7 8
25
5 0 2
7 1 4
9 0 1
11 1 5
13 0 5
15 1 1
17 0 3
19 1 2
21 0 4
23 1 3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.