-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCHEFSUBA2.cpp
72 lines (59 loc) · 978 Bytes
/
CHEFSUBA2.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
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <iterator>
#include <bits/stdc++.h>
using namespace std;
void count_occ(std::vector<int> v,int k,int sz)
{
//map<int ,int> hm;
//std::vector<int> v1;
//typedef std::map< vector <int> , int > hm;
int count=0;
int max=0;
unordered_map<int ,int >hm;
for (int i = 0; i < k; ++i)
{
//if(hm[v[i]]==0)
int a = v[i];
hm[a]+=1;
}
count=hm[1];
//printf("%d\n",hm[1]);
if(max < count)
{
max=count;
}
for (int i = k; i < sz ; ++i)
{
int a = v[i-k];
hm[a]-=1;
//printf("a and i %d %d\n",a,i);
int b =v[i];
hm[b]+=1;
count = hm[b];
if(max < count)
max=count;
}
printf("%d\n",max);
}
int main()
{
int sz;
scanf("%d",&sz);
std::vector<int> v;
//int v[sz];
for (int i = 0; i < sz; ++i)
{
int a;
scanf("%d",&a);
v.push_back(a);
// v[i]=a;
}
int k;
scanf("%d",&k);
count_occ(v,k,sz);
}