Sequence Formation (Contest)
Sequence Formation (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Sequence Formation (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement :
You are given an array A of size N. You have to divide this array A into two sequences B and C such that each element of array A is present in either sequence B or C exactly one. Find the maximum possible value of sum(B) - sum(C), where sum(B) represents the sum of elements in sequence B. Input The first line contains a single integer N. The second line contains N space separated integers.
Constraints: 1 ≤ N ≤ 105 -109 ≤ Ai ≤ 109 Output Print the maximum possible value of sum(B) - sum(C). Example Sample Input: 4 3 -2 0 1
Sample Output: 6
Explaination: B: {3, 1} C: {0, -2} Sum(B) = 4, Sum(C) = -2 Sum(B) - Sum(C) = 4 - (-2) = 4 + 2 = 6
link: