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.