Problem Solving/Baekjoon

[백준] 34692 아 마이마이 하고 싶다 - Data Structure / Java

graycode 2025. 12. 25. 14:39

 문제 링크

https://www.acmicpc.net/problem/34692

 

 풀이 코드

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        Queue<Long> pq = new PriorityQueue<>();
        int n = read(), m = read(), k = read();
        while (m-- > 0) pq.add(0L);
        while (n-- > 0) pq.add(pq.remove() + read());

        bw.write(pq.remove() > k ? "GO" : "WAIT");
        bw.flush();
    }

    private static int read() throws IOException {
        int c, n = System.in.read() & 15;
        while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);

        return n;
    }

}