Maximum of A[j]-A[i]+A[l]-A[k]
Time limit2sMemory limit512 MB
Given an array, choose four increasing indices i<j<k<l maximizing A[j]-A[i]+A[l]-A[k].
- Level
Medium4 of 10
- Topics
- Dynamic programming, Array, Brute force
- Solved
- No attempts yet
Problem
You are given an array of size . The indices of the array run from 1 to .
Write a program that finds the maximum value of over all index quadruples with .
Input
The first line contains the size of the array . ()
The second line contains the elements of in order. Every element is a natural number not greater than .
Output
Print the maximum value of over all with . This value can be negative.