Strange Function
Practice
3.7 (57 votes)
Ready
Mathematics
Open
Approved
Easy Medium
Mathamatics
Problem
79% Success 2142 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code
Kevin has an array A of N integers.
To make his array better Kevin can change every element by at most C. Formally, he can get any array B such that |Ai - Bi| ≤ C.
He wants to find the maximum of the following function among all possible arrays B:
Input format:
The first line of the input contains two space-separated integers N and C. The second line of the input contains N space-separated integers Ai.
Output format:
Output the single integer -- the maximum of the function.
Constraints:
- 1 ≤ N ≤ 105
- 0 ≤ Ai , C ≤ 107
- N ≤ 500 in test data worth 20% of all points
- N ≤ 2000 in test data worth 40% of all points
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
MathematicsBasic MathMath
Points:30
500 votes
Tags:
MathematicsSieveEasy-MediumBinary search algorithmMathematicsMathamatics
Points:30
29 votes
Tags:
MathematicsEasy-MediumMathematicsMathamatics
Editorial