한 줄로 서기

LJM·2023년 9월 2일
0

백준풀기

목록 보기
214/259

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

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));

        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());

        int[] height = new int[N];
        int[] line = new int[N];

        st = new StringTokenizer(br.readLine(), " ");
        for(int i = 0; i < N; ++i)
            height[i] = Integer.parseInt(st.nextToken());

        for (int i = 1; i <= N; i++) {
            int emptySpaces = height[i - 1];
            for (int j = 0; j < N; j++) {
                if (emptySpaces == 0 && line[j] == 0) {
                    line[j] = i;
                    break;
                }
                if (line[j] == 0) {
                    emptySpaces--;
                }
            }
        }
        for (int i = 0; i < N; i++) {
            System.out.print(line[i] + " ");
        }
    }
}
profile
게임개발자 백엔드개발자

0개의 댓글