• Home
  • About
    • 게임 개발자 유정룡 photo

      게임 개발자 유정룡

      포트폴리오

    • Learn More
    • Email
    • Github
    • Bitbucket
  • Projects
    • All Projects
    • All Tags

코딩테스트 백준 - 1449 수리공 항승

11 Oct 2021

Reading time ~1 minute

문제

그냥 주어진 수만큼 연결 되어있고 + 1 만큼 되어있으면 카운트를 하나 올려준다.

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int N , L;
	cin >> N >> L;

	vector<int> water(N);

	for(int i = 0 ; i <  N ; i++)
	{
		cin >> water[i];
	}
	sort(water.begin(), water.end());

	int count = 1;
	int start = water[0];
	for(int i = 1 ; i < N; i++)
	{
		if(water[i] - start > L - 1)
		{
			count++;
			start = water[i];
		}
	}

	cout << count << "\n";
}


CodingTest Share Tweet +1