41 lines
801 B
Java
41 lines
801 B
Java
// General imports
|
|
|
|
import java.util.Scanner;
|
|
|
|
public class WeightedDifference {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
|
|
// Write code here
|
|
|
|
int a = sc.nextInt();
|
|
int[] ar = new int[a];
|
|
for (int i = 0; i < a; i++) {
|
|
ar[i] = sc.nextInt();
|
|
}
|
|
|
|
long max = Long.MIN_VALUE;
|
|
int left = 0;
|
|
int right = ar.length - 1;
|
|
int gap = right - left;
|
|
int prevGap = 0;
|
|
while (gap > 0) {
|
|
int diff = ar[right] - ar[left] - (right - left);
|
|
max = diff > max ? diff : max;
|
|
if (gap == prevGap && right < ar.length - 1) {
|
|
left++;
|
|
right++;
|
|
} else {
|
|
gap--;
|
|
prevGap = gap;
|
|
left = 0;
|
|
right = gap;
|
|
}
|
|
}
|
|
|
|
System.out.println(max);
|
|
sc.close();
|
|
}
|
|
|
|
}
|