βSequence Formation (Contest)
Sequence Formation (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; i++){
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
int sumB = 0;
int sumC = 0;
for(int x = arr.length - 1; x >= 0; x--){
if(sumB > sumC){
sumC += arr[x];
} else{
sumB += arr[x];
}
}
System.out.print(sumB-sumC);
}
}
```Last updated