개발자 톡

연습문제 톡 [HSAT 5회 정기 코딩 인증평가 기출] 업무 처리

코드 로직의 어느 부분이 틀린건지 궁금합니다..

등록일
2024-07-18 20:14:58
조회수
113
작성자
jw8851066

subtask 1,2, 17~부터 다 틀립니다.. ㅜㅜ


import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] split = br.readLine().split(" ");
        int H = Integer.parseInt(split[0]);
        int K = Integer.parseInt(split[1]);
        int R = Integer.parseInt(split[2]);
        PriorityQueue<Work> left = new PriorityQueue<>((o1,o2) -> o1.index - o2.index);
        PriorityQueue<Work> right = new PriorityQueue<>((o1,o2) -> o1.index - o2.index);


        String[] temp1 = br.readLine().split(" ");
        for(int j = 0;j<K;j++){
            left.add(new Work(Integer.parseInt(temp1[j]),j));
        }

        String[] temp2 = br.readLine().split(" ");
        for(int j = 0;j<K;j++){
            right.add(new Work(Integer.parseInt(temp2[j]),j));
        }


        List<Box> list = new ArrayList<>();
        for(int i = 0;i<=H;i++) list.add(new Box());
        list.get(H).left = left;
        list.get(H).right = right;

        int answer = 0;
        for(int i = 1;i<=R;i++){
            for(int j = 0;j<=H;j++){

                if(j == H){
                    if(!list.get(H).left.isEmpty()){
                        Work poll = list.get(H).left.poll();
                        list.get(H-1).left.add(poll);
                    }
                    if(!list.get(H).right.isEmpty()){
                        Work poll = list.get(H).right.poll();
                        list.get(H-1).right.add(poll);
                    }
                    continue;
                }
                if(i % 2 ==0 && !list.get(j).right.isEmpty()){//짝수
                    Work poll = list.get(j).right.poll();
                    if(j != 0) list.get(j-1).right.add(poll);
                    else answer += poll.number;
                }else if(i % 2 == 1 && !list.get(j).left.isEmpty()){
                    Work poll = list.get(j).left.poll();
                    if(j != 0) list.get(j-1).left.add(poll);
                    else answer += poll.number;
                }
            }
        }

        System.out.println(answer);
    }
}
class Box{
    PriorityQueue<Work> left = new PriorityQueue<>((o1,o2) -> o1.index - o2.index);
    PriorityQueue<Work> right = new PriorityQueue<>((o1,o2) -> o1.index - o2.index);

}

class Work{
    int number;
    int index;

    public Work(int a, int b){
        number = a;
        index = b;
    }

    @Override
    public String toString(){
        return "number = " + number + " : index = " + index;
    }
}


#[HSAT_5회_정기_코딩_인증평가_기출]_업무_처리

이 카테고리의 톡 더보기