-
Notifications
You must be signed in to change notification settings - Fork 0
/
empty_graph.cpp
45 lines (43 loc) · 1.16 KB
/
empty_graph.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
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while(t--)
{
int n, k; cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {cin >> a[i];}
int l = 1, r = 1e9;
while (l < r) {
int mid = (l + r + 1)/2;
vector<int> b = a;
int ops = 0;
for (int i = 0; i < n; ++i) {
if (b[i] * 2 < mid) {
b[i] = 1e9;
ops++;
}
}
if (k == ops) {
bool good = false;
for (int j = 0; j < n - 1; ++j) {
if (min(b[j], b[j+1]) >= mid) {
good = true;
break;
}
}
if (good) {l = mid;}
else {r = mid - 1;}
}
else if (k - ops == 1 && *max_element(b.begin(), b.end()) >= mid) {l = mid;}
else if (k - ops > 1) {l = mid;}
else {r = mid - 1;}
}
cout << l << "\n";
}
return 0;
}