Baekjoon 11003
최솟값 찾기


QUESTION ❔



CODE ⌨️

#include <iostream>
#include <deque>

using namespace std;

struct pnt
{
	int first;
	int second;
};

int N, L;
int arr[5000000];

deque<pnt> DQ;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> N >> L;

	for (int i = 0; i < N; i++)
	{
		cin >> arr[i];
	}

	for (int i = 0; i < N; i++)
	{
		if (!DQ.empty() && DQ.front().second <= i - L)
		{
			DQ.pop_front();
		}

		while (!DQ.empty() && DQ.back().first > arr[i])
		{
			DQ.pop_back();
		}

		DQ.push_back({ arr[i], i });

		cout << DQ.front().first << " ";
	}

	cout << "\n";

	return 0;
}



RESULT 💛



SIMPLE DISCUSSION ✏️

덱(Deque) 관련 문제였다.



SOURCE 💎

Baekjoon_Link 👈 Click here


*****
NOT A TALENT ❎ NOT GIVING UP ✅
CopyRight ⓒ 2022 DCherish All Rights Reserved.