-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpartition.java
More file actions
48 lines (39 loc) · 1.09 KB
/
Copy pathpartition.java
File metadata and controls
48 lines (39 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.Arrays;
import java.util.Scanner;
import java.io.*;
import java.util.*;
public class partition {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int size = sc.nextInt() + 2;
int list [] = new int [size];
list[0] = 0;
list[size-1] = n;
for(int i = 1; i < size-1; i++)
{
list[i] = sc.nextInt();
}
List<Integer> parts = new ArrayList<Integer>();
for(int i = 1; i < size; i++)
{
for(int j = 0; j < size; j++)
{
int item = list[i] - list[j];
if(item > 0 && !parts.contains(item))
{
parts.add(item);
}
}
}
Collections.sort(parts);
for(int i = 0; i < parts.size(); i++)
{
System.out.print(parts.get(i));
if(i != parts.size()-1)
{
System.out.print(" ");
}
}
}
}