-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpails.java
76 lines (62 loc) · 2 KB
/
pails.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.*;
import java.io.*;
public class pails {
static class Solver {
void solve(InputReader in, PrintWriter out) throws Exception {
// Here goes your code
int x = in.nextInt();
int y = in.nextInt();
int m = in.nextInt();
int ans = 0;
for(int xx = 0; xx * x <= m; xx++){
for(int yy = 0; xx * x + yy * y <= m; yy++){
if(xx * x + yy * y > ans) {
ans = xx * x + yy * y;
}
}
}
out.print(ans);
}
}
public static void main(String... args) throws Exception {
InputReader in = new InputReader("pails" + ".in");
PrintWriter out = new PrintWriter("pails" + ".out");
new Solver().solve(in, out);
out.close();
in.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream is) throws Exception {
reader = new BufferedReader(new InputStreamReader(is));
}
InputReader(String inFilePath) throws Exception {
this(new FileInputStream(inFilePath));
}
InputReader() throws Exception {
this(System.in);
}
String next() throws Exception {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
String nextLine() throws Exception {
return reader.readLine();
}
int nextInt() throws Exception {
return Integer.parseInt(next());
}
long nextLong() throws Exception {
return Long.parseLong(next());
}
double nextDouble() throws Exception {
return Double.parseDouble(next());
}
void close() throws Exception {
reader.close();
}
}
}