#181. 检查有序数组相邻三元组差值
检查有序数组相邻三元组差值
Check Adjacent Triplet
Background
Congcong is currently organizing some score data. He wants to find if there are any specific patterns within it.
Problem Description
Given an array of scores sorted in increasing order, return true if the array contains adjacent scores such that the difference between the maximum and minimum score within that triplet is at most . For example, with triplets like {3, 4, 5} or {3, 5, 5}, it should return true.
Input Format
Input is given from Standard Input in the following format.
score_1 score_2 ... score_n(representing an array of integers, elements separated by spaces)
Output Format
Output is printed to Standard Output in the following format.
trueorfalse
Sample
3 4 5
true
3 4 6
false
1 3 5 5
true
Sample Explanation
Sample 1: The array is [3, 4, 5]. These three numbers are adjacent, and the difference between the maximum and minimum is , which satisfies the condition (at most ). Thus, true is returned.
Sample 2: The array is [3, 4, 6]. These three numbers are adjacent, but the difference between the maximum and minimum is , which does not satisfy the condition (at most ). Thus, false is returned.
Sample 3: The array is [1, 3, 5, 5].
- Consider the adjacent triplet
[1, 3, 5]. The difference between the maximum and minimum is , which does not satisfy the condition. - Consider the adjacent triplet
[3, 5, 5]. The difference between the maximum and minimum is , which satisfies the condition. Thus,trueis returned.
Constraints
Time limit: second. Memory limit: MiB.