PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000070. Định mệnh (Destiny)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Định mệnh (Destiny)
Destiny
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
For each , print the smallest value occurring strictly more than times in . Print -1 if none exists.
Input
Read , the array, and triples .
Output
Print the smallest valid value or -1 for each query.
Subtasks
- Subtask 1 (10 points): , . ; ; .
- Subtask 2 (20 points): , . ; ; .
- Subtask 3 (25 points): , . ; ; .
- Subtask 4 (45 points): , . ; ; .
Examples
Input
4 2
1 1 2 2
1 3 2
1 4 2
Output
1
-1
Explanation
In , the threshold is ; value 1 occurs twice. In , no value occurs more than times.