IT 정보/알고리즘(백준, BOJ)

[백준-BOJ] 2875

Dalyoung 2021. 2. 18. 22:23
728x90

www.acmicpc.net/problem/2875

 

2875번: 대회 or 인턴

첫째 줄에 N, M, K가 순서대로 주어진다. (0 ≤ M ≤ 100, 0 ≤ N ≤ 100, 0 ≤ K ≤ M+N),

www.acmicpc.net

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
 
public class Main {
    public static void main(String[] args) throws IOException {
        Main m = new Main();
        m.doit();
    }
     
     
     
    public void doit() throws IOException{
       // System.setIn(new FileInputStream("input.txt"));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N, M, K;
        String [] input = br.readLine().split(" ");
        N = Integer.parseInt(input[0]);
        M = Integer.parseInt(input[1]);
        K = Integer.parseInt(input[2]);
        
        while(N > 0 && M > 0 && K > 0){
        	if(N >= 2 * M){
        		N--;
        	}else{
        		M--;
        	}
        	K--;
        }
        int ret = 0;
        while(N > 1 && M > 0){
        	if(N >= 2*M){
        		N -= 2;
        		M--;
        		ret++;
        	}else{
        		M--;
        	}
        }

        System.out.println(ret);
        br.close();
    }
}
728x90
반응형

'IT 정보 > 알고리즘(백준, BOJ)' 카테고리의 다른 글

[백준-BOJ] 3046  (0) 2021.02.24
[백준-BOJ] 2985  (0) 2021.02.24
[백준-BOJ] 2864  (0) 2021.02.18
[백준-BOJ] 2839  (0) 2021.02.18
[백준-BOJ] 2806  (0) 2021.02.18