Universal Cup Judging System

Universal Cup

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓
統計

長さ $N$ の 2 つの列 $A$ と $B$ が与えられます。

すべての $i$ ($1 \le i \le N$) に対して、先頭 $i$ 項の LIS(最長増加部分列)の長さが $A_i$ であり、かつ先頭 $i$ 項の LDS(最長減少部分列)の長さが $B_i$ であるような $(1, 2, \dots, N)$ の順列 $C$ が存在するかどうかを判定してください。

そのような順列が存在する場合は、1 つ構築してください。

入力

入力は以下の形式で与えられます:

$$N$$ $$A_1\ A_2\ \dots\ A_N$$ $$B_1\ B_2\ \dots\ B_N$$

制約

  • $1 \le N \le 5 \times 10^5$
  • $1 \le A_i \le N$ ($1 \le i \le N$)
  • $1 \le B_i \le N$ ($1 \le i \le N$)
  • 入力される値はすべて整数である。

出力

条件を満たす順列が存在しない場合は $-1$ を出力してください。存在する場合は、順列 $C$ の要素を表す $N$ 個の整数を空白区切りで出力してください。条件を満たす順列が複数存在する場合は、どれを出力しても正解となります。

入出力例

入力例 1

3
1 1 2
1 2 2

出力例 1

2 1 3

入力例 2

4
1 1 2 2
1 2 2 3

出力例 2

3 2 4 1

入力例 3

4
1 2 2 3
1 2 2 2

出力例 3

-1

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2544EditorialOpen题解KobicGendView
#1488EditorialOpen题解jianglyView

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.