PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000009. Dora tìm đoạn phù hợp (Dora and Search)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dora tìm đoạn phù hợp (Dora and Search)
Dora and Search
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Dora is given a permutation of length . A permutation contains each integer from to exactly once. She wants to choose a contiguous segment from position to position , where positions are numbered starting from .
A segment is valid when neither endpoint equals the minimum or the maximum of the values within that segment. Find indices of any valid segment. If none exists, print -1.
Input
- The first line contains the integer , the length of the permutation.
- The second line contains exactly integers in left-to-right order.
Output
Print -1 if no valid segment exists. Otherwise, print two integers , , on one line. Any valid segment is accepted.
Subtasks
- Subtask 1 (20 points): ; for every ; is a permutation of .
- Subtask 2 (30 points): ; for every ; is a permutation of .
- Subtask 3 (50 points): ; for every ; is a permutation of .
Examples
Input
4
2 1 4 3
Output
1 4
Explanation
The whole segment [1,4] has minimum 1 and maximum 4 in its interior. Its endpoints 2 and 3 are neither extreme.