Partition
题意翻译
## 题目描述
给定一个由n个整数组成的序列。您可以将这个序列分割成两个序列b和c,这样每个元素都完全属于其中一个序列。B是属于b的元素的和,C是属c的元素的和(如果其中一些序列是空的,那么它的和是0)。求B-C的最大可能值?
## 输入输出格式##
## 输入格式
第一行包含一个整数n (1<=n<=100 1<= 100)——a中的元素个数。 第二行包含n个整数。a1~an序列a的元素。
## 输出格式
B-C的最大可能值,B是序列b的元素之和,C是序列c元素的和。
## 说明
在第一个示例中,我们可以选择b = 1,0,c=2。然后B=1,C =−2,B−C=3。 在第二个示例中,我们选择b=16、23、16、15、42、8,c=(一个空序列)。这时B=120,C= 0,B−C = 120。
感谢@周靖凯 提供的翻译
题目描述
You are given a sequence $ a $ consisting of $ n $ integers. You may partition this sequence into two sequences $ b $ and $ c $ in such a way that every element belongs exactly to one of these sequences.
Let $ B $ be the sum of elements belonging to $ b $ , and $ C $ be the sum of elements belonging to $ c $ (if some of these sequences is empty, then its sum is $ 0 $ ). What is the maximum possible value of $ B-C $ ?
输入输出格式
输入格式
The first line contains one integer $ n $ ( $ 1<=n<=100 $ ) — the number of elements in $ a $ .
The second line contains $ n $ integers $ a_{1} $ , $ a_{2} $ , ..., $ a_{n} $ ( $ -100<=a_{i}<=100 $ ) — the elements of sequence $ a $ .
输出格式
Print the maximum possible value of $ B-C $ , where $ B $ is the sum of elements of sequence $ b $ , and $ C $ is the sum of elements of sequence $ c $ .
输入输出样例
输入样例 #1
3
1 -2 0
输出样例 #1
3
输入样例 #2
6
16 23 16 15 42 8
输出样例 #2
120
说明
In the first example we may choose $ b={1,0} $ , $ c={-2} $ . Then $ B=1 $ , $ C=-2 $ , $ B-C=3 $ .
In the second example we choose $ b={16,23,16,15,42,8} $ , $ c={} $ (an empty sequence). Then $ B=120 $ , $ C=0 $ , $ B-C=120 $ .