Universal Cup Judging System

Universal Cup

시간 제한: 2.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓
통계

길이가 $N$인 두 수열 $A$와 $B$가 주어집니다.

모든 $i$ ($1 \le i \le N$)에 대하여, 길이가 $i$인 접두사의 LIS(최장 증가 부분 수열)의 길이가 $A_i$이고, 길이가 $i$인 접두사의 LDS(최장 감소 부분 수열)의 길이가 $B_i$가 되도록 하는 $(1, 2, \dots, N)$의 순열 $C$가 존재하는지 판별하세요.

그러한 순열이 존재한다면 하나를 구성하세요.

입력

입력은 다음 형식으로 주어집니다:

$$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.