-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflexible.java
50 lines (34 loc) · 868 Bytes
/
flexible.java
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
49
50
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
public class flexible {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int length = scan.nextInt();
int cuts = scan.nextInt();
ArrayList<Integer> sizes = new ArrayList<>();
int[] rooms = new int[cuts+2];
rooms[0] = 0;
rooms[rooms.length-1] = length;
for(int i=1; i < rooms.length-1; i++)
{
rooms[i] = scan.nextInt();
}
for(int i=0; i < rooms.length; i++)
{
for(int j=i+1; j < rooms.length; j++)
{
sizes.add(rooms[j] - rooms[i]);
}
}
Collections.sort(sizes);
HashSet<Integer> list = new HashSet<>(sizes);
for(int i : list)
{
System.out.println(i + " ");
}
scan.close();
}
}