PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000018. Có tồn tại cặp số chênh lệch X? (Gap Existence)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Có tồn tại cặp số chênh lệch X? (Gap Existence)
Gap Existence
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an integer array and an integer .
Determine whether two indices in the range from to exist such that . The indices are allowed to be equal, meaning the same element can be used twice. Both and array elements may be negative, zero, or positive.
Input
The first line contains integers : the array length and the required difference.
The second line contains exactly integers .
Output
Print Yes if such indices exist; otherwise print No. Use exactly the displayed capitalization.
Subtasks
- Subtask 1 (20 points): ; ; for all ; indices are allowed.
- Subtask 2 (30 points): ; ; for all ; indices are allowed.
- Subtask 3 (50 points): ; ; for all ; indices are allowed.
Examples
Input
6 5
3 1 4 1 5 9
Output
Yes
Explanation
Choose and . Then , so the answer is Yes. The indices are allowed to be identical; in particular, when , taking always works.