Coding Test - cpp/Greedy
[백준 1449: 수리공 항승] - C++
에드윈H
2021. 3. 16. 16:48
1449번: 수리공 항승
첫째 줄에 물이 새는 곳의 개수 N과 테이프의 길이 L이 주어진다. 둘째 줄에는 물이 새는 곳의 위치가 주어진다. N과 L은 1,000보다 작거나 같은 자연수이고, 물이 새는 곳의 위치는 1,000보다 작거나
www.acmicpc.net
#include<iostream>
#include<algorithm>
using namespace std;
int list[1001];
int main()
{
int ans = 1;
int N, L;
cin >> N >> L;
for (int i = 0; i < N; i++)
cin >> list[i];
sort(list, list + N);
int st = list[0];
for (int i = 1; i < N; i++)
{
if (list[i] - st + 1 > L)
{
ans++;
st = list[i];
}
}
cout << ans;
return 0;
}