Dev.baelanche

[백준 2979] 트럭 주차 본문

Data Structure & Algorithm/PS - JAVA

[백준 2979] 트럭 주차

baelanche 2019. 6. 29. 17:33
반응형

 

 

도착시간과 떠난시간 사이의 트럭 개수를 출력하여 맞는 요금을 부여하면 된다.

 

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        int truck[][] = new int[3][2];
        for(int i=0; i<3; i++)
            for(int j=0; j<2; j++)
                truck[i][j] = sc.nextInt();
        
        int cost = 0;
        for(int time=1; true; time++) {
            int cnt = 0;
            for(int i=0; i<3; i++)
                if(truck[i][0] <= time && truck[i][1] > time)
                    cnt++;
            
            if(cnt == 1) cost += a;
            else if(cnt == 2) cost += b*2;
            else if(cnt == 3) cost += c*3;
            
            if(time > truck[0][1] && time > truck[1][1] && time > truck[2][1]) break;
        }
        System.out.println(cost);
    }
}
반응형

'Data Structure & Algorithm > PS - JAVA' 카테고리의 다른 글

[백준 10815] 숫자 카드  (0) 2019.06.29
[백준 1009] 분산처리  (0) 2019.06.29
[백준 1547] 공  (0) 2019.06.29
[백준 14500] 테트로미노  (0) 2019.06.29
[백준 6603] 로또  (0) 2019.06.29
Comments