-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21036.cpp
More file actions
85 lines (64 loc) · 1.52 KB
/
21036.cpp
File metadata and controls
85 lines (64 loc) · 1.52 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
using namespace std;
const ll INF = 1e9 + 7;
const ll DIV = 987654321;
ll n, m, k;
ll arr[101010];
ll val[101010];
int main()
{
fastio;
cin >> n >> m >> k;
vector<ll> tmp;
for(int i=0 ;i < m;i++){
cin >> arr[i];
tmp.push_back(arr[i]);
}
sort(tmp.begin(), tmp.end());
tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
for(int i =0 ;i < tmp.size();i++){
arr[i] = tmp[i];
}
m = tmp.size();
priority_queue<pair<ll,ll>> pq;
for(int i =0 ;i < m;i++){
ll l, r;
if(i == 0){
l = 1;
}
else{
l = (arr[i] + arr[i - 1] + 1) / 2;
}
if(i == m - 1) r = n;
else{
r = (arr[i] + arr[i+1])/2;
}
val[i] = r - l + 1;
pq.push({val[i], i});
}
ll ans = 0;
for(int i = 0; i < min(m,k);i++){
while(pq.top().first != val[pq.top().second]){
auto[a, idx] = pq.top();
pq.pop();
pq.push({val[idx], idx});
}
auto[x, idx] = pq.top();
pq.pop();
ans += x;
if(idx > 0){
if(( arr[idx] - arr[idx - 1]) % 2 == 0){
val[idx - 1]--;
}
}
if(idx + 1 < m){
if((arr[idx + 1] - arr[idx]) % 2 == 0){
val[idx + 1]--;
}
}
}
cout << ans << "\n";
return 0;
}