-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorld Domination Fun.cpp
61 lines (44 loc) · 963 Bytes
/
World Domination Fun.cpp
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
57
58
59
60
61
#include <iostream>
#include <cstring>
using namespace std;
typedef long long int ll;
const int MAX = 100005;
const int MAX_HEIGHT = 2000000001;
ll arr[MAX], temp[MAX];
int N, M, K;
bool check(ll cap){
ll used = 0;
for (int i=1; i<=N; i++){
temp[i] = arr[i] - arr[i-1];
}
for (int i=1; i<=N; i++){
temp[i] += temp[i-1];
if (temp[i] < cap){
ll d = cap - temp[i];
used += d;
temp[i] += d, temp[min(N+1, i+M)] -= d;
}
}
return used <= K;
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> N >> M >> K;
arr[0] = temp[0] = 0;
for (int i=1; i<=N; i++){
cin >> arr[i];
}
ll low = 1;
ll high = MAX_HEIGHT;
while (low < high){
ll mid = (low + high) / 2;
if (check(mid)){
low = mid + 1;
} else {
high = mid;
}
}
cout << low - 1;
return 0;
}