#C1588. Three-Item Purchase Problem
Three-Item Purchase Problem
Three-Item Purchase Problem
You are given a list of N items with their respective prices and an integer C representing the maximum allowed total cost. Your task is to determine whether there exists a combination of exactly three distinct items such that their total cost is less than or equal to C. Note that if the number of items is less than three, the answer is automatically "NO".
Constraints:
- 2 ≤ N ≤ 1000
- 0 ≤ C ≤ 1000000
- 1 ≤ Pi ≤ 10000, where Pi is the price of the i-th item
Hint: In a sorted list, the sum of the three smallest values is the minimum possible sum for any three distinct items. Use this fact to simplify your solution.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains two integers N and C, representing the number of items and the maximum allowed cost respectively.
- The second line contains N space-separated positive integers representing the prices of the items.
outputFormat
Output a single line to stdout containing either "YES" if there exists a valid combination, or "NO" otherwise.
## sample5 10
1 2 3 8 5
YES