-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_1065C.cpp
More file actions
56 lines (46 loc) · 748 Bytes
/
Copy pathCF_1065C.cpp
File metadata and controls
56 lines (46 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <algorithm>
using namespace std;
int towers[200000];
int heightCount[200001];
int main() {
int n, k;
cin >> n >> k;
int minheight = 200000;
int maxHeight = 0;
for (int i = 0; i < n; i++)
{
cin >> towers[i];
minheight = min(minheight, towers[i]);
maxHeight = max(maxHeight, towers[i]);
heightCount[towers[i]]++;
}
// 3 1 2 2 4
/* 4:1
* 3:2
* 2:4
* 1:5
*/
for (int i = 200000; i > 0; i--)
{
heightCount[i - 1] += heightCount[i];
}
long long ans = 0;
int sum = 0;
for (int i = 200000; i > minheight; i--)
{
sum += heightCount[i];
if (sum > k)
{
sum -= heightCount[i];
ans++;
sum = 0;
i++;
}
}
if (maxHeight != minheight)
{
++ans;
}
cout << ans << endl;
}