Replacing numbers

4

3 votes
Dynamic Programming, Algorithms, Medium, Introduction to Dynamic Programming 1
Problem

You are given an array of size N. Your task is to replace any one element of the array with its corresponding square.

Find the maximum sum of subarrays after performing the task exactly once.

Input format

  • First line: An integer N denoting the size of the array
  • Second line: N space-separated integers denoting the elements of the array

Output format

  • Print the maximum sum according to the problem statement.

Constraints
1N5105

107A[i]107

Sample Input
3
1 -4 2
Sample Output
19
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Square of -4 is 16. The array now becomes : {1,16,3}. Sum of subarray A[1,3] is 19.

Editor Image

?