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
|
package greedy;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main2875_대회or인턴 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
if (K == 0) {
process(N, M);
} else {
while (K != 0) {
if (N >= 2 * M) {
N--;
K--;
}else {
M--;
K--;
}
}
process(N, M);
}
}// end of main
public static void process(int N , int M) {
if (N >= 2 * M) {
System.out.println(M);
return;
} else {
System.out.println(N / 2);
return;
}
}
}// end of class
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
'Algorithm 문제풀이 > greedy' 카테고리의 다른 글
[BOJ] 백준 2875 - 대회or인턴 (JAVA) (0) | 2019.06.25 |
---|---|
[BOJ] 백준 10610 - 30 (JAVA) (0) | 2019.06.19 |
[BOJ] 백준 1931 - 회의실배정 (JAVA) (0) | 2019.06.18 |
[BOJ] 백준 5585 - 거스름돈 (JAVA) (0) | 2019.06.18 |
[BOJ] 백준 11047 - 동전 (JAVA) (0) | 2019.06.16 |