forked from Code-Cube-NITP/Competitive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnot_all_flavours.cpp
More file actions
executable file
·52 lines (46 loc) · 1.42 KB
/
not_all_flavours.cpp
File metadata and controls
executable file
·52 lines (46 loc) · 1.42 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
// g++ not_all_flavours.cpp -o not_all_flavours && ./not_all_flavours
/*
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
int32_t main(){
fastio;
int n, k;
w(t){
cin >> n >> k;
vin count(k+1, 0);
vin arr(n);
loop(0, n, i) cin >> arr[i];
int ans = 0;
int types = 0;
int start = 0;
int i;
for(i = 0; i < n; i++){
if(count[arr[i]] == 0){
types++;
count[arr[i]]++;
if(types >= k){
ans = ans > i-start ? ans : i-start;
while(types >= k){
count[arr[start]]--;
if(count[arr[start]] == 0) types--;
start++;
}
}
}
else count[arr[i]]++;
}
ans = ans > i-start ? ans : i-start;
cout << ans << endl;
}
}