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
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
MathematicsBasic MathMath
Points:30
Tags:
Easy-Medium
3.ZrZr
Points:20
90 votes
Tags:
ApprovedEasyFactorizationMathNumber TheoryOpen
Editorial
Login to unlock the editorial