반응형
반응형
//#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
int main()
{
int n, l, s, count = 0;
bool cover = false;
vector <int> leak;
cin >> n >> l;
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
leak.emplace_back(a);
}
if (l == 1)
{
cout << n;
return 0;
}
if (l == 0)
{
return 0;
}
sort(leak.begin(), leak.end());
s = leak[0];
for (int i = 1; i < n; i++)
{
if (leak[i] - s >= l)
{
count++;
s = leak[i];
}
}
cout << count;
}반응형
'알고리즘 > 그리디 알고리즘' 카테고리의 다른 글
| [백준] 1213번 - 팰린드롬 만들기 (0) | 2023.02.28 |
|---|---|
| [백준] 2720 - 세탁소 사장 동혁 (0) | 2023.02.11 |
| [백준] 1049 - 기타줄 (0) | 2023.02.08 |
| [백준] 2863 - 5 와 6의 차이 (0) | 2023.02.05 |
| [백준] 1439 - 뒤집기 (0) | 2023.02.01 |