forked from div-hacks/Be-Creative-Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Little_elephant_alcohol.cpp
78 lines (68 loc) · 1.92 KB
/
Little_elephant_alcohol.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define sqr(a) (1LL * (a) * (a))
using namespace std;
#ifdef LOCAL
#include <bug.h>
#else
#define mt(...)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
// https://www.codechef.com/JAN13/problems/LEALCO
//-----------------------------------------------------------------------//
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tt;
cin >> tt;
auto check = [](vector<int> &arr, int n, int k, int m) {
for (int i = 0; i <= n - k; ++i) {
int curr_max = -inf;
int cnt = 0;
for (int j = i; j < i + k; ++j) {
if (arr[j] == curr_max) cnt++;
else if (arr[j] > curr_max) {
curr_max = arr[j];
cnt = 1;
}
}
// mt(i, cnt)
if (cnt >= m) return false;
}
return true;
};
while (tt-- > 0) {
int n, k, m;
cin >> n >> k >> m;
vector<int> arr(n);
for (int &r : arr) {
cin >> r;
}
int res = inf;
for (int mask = 0; mask < (1 << n); ++mask) {
vector<int> add;
add.reserve(__builtin_popcount(mask));
for (int i = 0; i < n; ++i) {
if (mask & (1 << i)) {
add.emplace_back(i);
}
}
for (int &i : add) {
arr[i]++;
}
if (check(arr, n, k, m)) {
res = min(res, (int) add.size());
}
for (int &i : add) {
arr[i]--;
}
}
cout << (res == inf ? -1 : res) << '\n';
}
return 0;
}