AlgoUniversity
  • Go Back
Discussion
Maximum Partitions :

Author

Yash Sahijwani

Difficulty Level : Easy

Submissions : 300

Asked In : Barclays

Marks :10

: 2 | : 1

You are given an array $$$a$$$ consisting of $$$n$$$ integers. You can make any number of partitions in the array such that when you combine all these partitions, the value of the special sum that is obtained is maximum. If you make $$$k$$$ partitions in the array, the the special sum is defined as $$$P_{1} - P_{2} + P_{3} + .... + (-1)^{k+1}P_{k}$$$. Here $$$P_{i}$$$ is defined as the summation of all integers in that partition.

Input

The first line of input consists of a single integer $$$n$$$ - the total number of elements in the array. The next line consists of $$$n$$$ space separated integers - the elements of the array a. $$$(-10^9 \leq a[i] \leq 10^9)$$$.

Output

Output a single integer - the maximum special sum that can be obtained by partitioning the array.

Example

Input
3
1 -2 3
Output
6

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.