-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloan.txt
58 lines (45 loc) · 1.56 KB
/
loan.txt
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
import java.io.*;
import java.util.StringTokenizer;
public class loan {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("loan.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("loan.out")),true);
StringTokenizer st = new StringTokenizer(f.readLine());
long n = Long.parseLong(st.nextToken());
long k = Long.parseLong(st.nextToken());
long m = Long.parseLong(st.nextToken());
long pos = 0;
for(Long a =n; a>0; a/=2){
while ((pos+a)<n && verify(n,k,m,pos+a)){
pos+=a;
}
}
out.println(pos);
out.close();
}
public static boolean verify(long N, long K, long M, long X){
long current =0;
long counter = 0;
while(counter<=K&¤t<=N){
long y = Math.max((N-current)/X,M);
if(y==M){
counter+=(N-current)/y;
current+= ((N-current)/y)*y;
if(current<N){
current+=y;
counter++;
}
break;
}else{
long target =N-X*(y)+1;
counter+=(target-current)/y;
current+= ((target-current)/y)*y;
if(current<target){
current+=y;
counter++;
}
}
}
return current>=N&&K>=counter;
}
}