27527번: 배너 걸기 (acmicpc.net)

 

27527번: 배너 걸기

현대오토에버는 현대자동차그룹의 모빌리티 소프트웨어 전문 기업으로서, In-Car와 Out-Car 영역 전반의 소프트웨어와 인프라를 안정적, 효율적, 혁신적으로 지원하는 'Mobility SW Provider' 역할을 수

www.acmicpc.net

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    static int[] A = new int[1000001];
    static int[] heights;
    static int N;
    static int M;
    static int dest;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        N = Integer.parseInt(s[0]);
        M = Integer.parseInt(s[1]);


        String[] heights_ = br.readLine().split(" ");
        heights = new int[N];

        for(int i = 0; i < N; i++)
            heights[i] = Integer.parseInt(heights_[i]);

        if ((9 * M) % 10 == 0) {
            dest = (9 * M) / 10;
        }
        else {
            dest = (9 * M) / 10;
            dest++;
        }
        System.out.println(isPossible());
    }
    public static String isPossible(){
        for(int i = 0; i < M; i++){
            A[heights[i]] += 1;
            if(A[heights[i]] == dest)
                return "YES";
        }

        for(int i = 1; i <= N - M; i++){
            A[heights[i - 1]] -= 1;
            A[heights[i + M - 1]] += 1;
            if(A[heights[i + M - 1]] == dest)
                return "YES";
        }

        return "NO";
    }
}

+ Recent posts