-
Notifications
You must be signed in to change notification settings - Fork 1
/
1107.java
43 lines (35 loc) · 1.2 KB
/
1107.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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String line = br.readLine();
if (line == null)
break;
if (line.isEmpty())
continue;
int[] ac = Arrays.stream(line.trim().split(" "))
.mapToInt(Integer::parseInt)
.toArray();
int A = ac[0];
int C = ac[1];
line = br.readLine();
if (line == null || line.isEmpty())
break;
int[] blocos = Arrays.stream(line.trim().split(" "))
.mapToInt(Integer::parseInt)
.toArray();
int resposta = 0;
for (int i = 1; i < C; ++i) {
if (blocos[i] > blocos[i - 1]) {
resposta += blocos[i] - blocos[i - 1];
}
}
resposta += A - blocos[C - 1];
System.out.println(resposta);
}
}
}