Computer Science, asked by kinjalshrawagi6, 7 months ago

There is an array of N integers. You are required to make any number of partitions in the array such that the special sum o
all the partitions combined is maximized.
If you make K partitions then the Special Sum is defined as P1 – P2 + P3 – P4 + P5.....+(-1)(K-1) P2
Here P; is defined as the summation of all integers in that partition.
Input format
The first line consists of an integer N that denotes the number of integers in the array.
The second line consists of N integers that denote the values of the array.
Output format
Print aa single integer which denotes the maximum value of the special sum that can be obtained by any number of
partitions.
Constraints
1 -10^9<_ values inside array<_10^9

input
5
1 -2 -3 2 1

output
9​

Answers

Answered by Anonymous
21

Answer:

Input: arr[] = {1, 6, 11, 5}

Output: 1

Explanation:

Subset1 = {1, 5, 6}, sum of Subset1 = 12

Subset2 = {11}, sum of Subset2 = 11

Explanation:

MARK ME AS A BRAINLEIST

AND FOLLOW ME AND THANKS MY ANSWERS PLEASE

Answered by aburaihana123
0

Answer:

The partition of the output value 9 is  1 - (-2 + -3) + (2 + 1)

Explanation:

Partion can be denoted as  P1 – P2 + P3 – P4 + P5.....+(-1)(K-1) P2

Input :

The number N, which represents the array's total number of integers, appears on the first line of input.

N integers on the second line of input represent the values of the array.

Output:

A single integer that represents the highest Special Sum value that may be reached by any number of partitions.

Constraint :

1 ≤ N ≤ 100000

-10^{9} ≤ values inside array ≤ 10^{9}

Sample Input:

Total no = 5

1 , -2 ,-3 ,+2, 1

Sample output

9

Final answer:

You can divide the space into three parts starting with [0, 0], [1, 2], and [3, 4].

Such partitions special value is equal to 1 - (-2 + -3) + (2 + 1)

As the result the output is 9

SPJ3

Similar questions