-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrace.java
More file actions
62 lines (52 loc) · 1.61 KB
/
Copy pathrace.java
File metadata and controls
62 lines (52 loc) · 1.61 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.lang.*;
import java.util.*;
import java.io.*;
public class race {
public static void main(String[] args) {
File f = new File("race.in");
try(Scanner in = new Scanner(f)){
try(PrintWriter writer = new PrintWriter("race.out", "UTF-8")){
int k = in.nextInt();
int n = in.nextInt();
for(int i = 0;i<n;i++){
int x = in.nextInt();
int top = 0;
for(int j = 0;j<=x;j++){
top+= j;
}
int total = 1;
int max = 1;
int seconds = 1;
boolean flag = true;
while(total<k){
if(total + arith(x,max+1) <= k){
total = total + max + 1;
max += 1;
seconds+=1;
}else if(total + arith(x,max) <= k){
total = total + max;
seconds+=1;
}else if(total + arith(x,max-1) <= k) {
total = total + max - 1;
seconds += 1;
max -=1;
}
}
writer.println(seconds);
if(i == n-1){
writer.close();
}
}
}catch(IOException e){
}
}catch(IOException e){
}
}
public static int arith(int x, int y){
int total = 0;
for(int i = x; i<=y;i++){
total += i;
}
return total;
}
}