Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

Вам даны две последовательности $A$ и $B$ длины $N$.

Определите, существует ли перестановка $C$ чисел $(1, 2, \dots, N)$, такая что для всех $i$ ($1 \le i \le N$) длина LIS (наибольшей возрастающей подпоследовательности) префикса длины $i$ равна $A_i$, а длина LDS (наибольшей убывающей подпоследовательности) префикса длины $i$ равна $B_i$.

Если такая перестановка существует, постройте одну из них.

Входные данные

Входные данные заданы в следующем формате:

$$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$. В противном случае выведите $N$ целых чисел через пробел, представляющих элементы перестановки $C$. Если таких перестановок несколько, будет принята любая из них.

Примеры

Входные данные 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.