Advertisement
Rofyda_Elghadban1

Untitled

Mar 13th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define pi 3.141592654
  5. #define NUM 1e18
  6. #define Mod 1'000'000'007
  7. #define fixed(n) fixed<<setprecision(n)
  8. #define cin(v) for(auto &i:v) cin >> i ;
  9. #define cout(v) for(auto &i:v) cout << i <<" ";
  10. #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11. #define small(x) (x>=97&&x<=122)
  12. #define capital(x) (x>=65&&x<=90)
  13. #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14. #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15. #define sz(x) (int)(x.size())
  16. #define all(v) ((v).begin()), ((v).end())
  17. #define allr(v) ((v).rbegin()), ((v).rend())
  18. #define updmax(a,b) a=max(a,b)
  19. #define updmin(a,b) a=min(a,b)
  20. #define ceil(a,b) ((a/b)+(a%b?1:0))
  21. /* asc -> 1 2 3 ,des -> 3 2 1 */
  22.  
  23. /***********************************************************************************/
  24. using namespace std;
  25. void Rofyda_Elghadban(){
  26. #ifndef ONLINE_JUDGE
  27. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  28. #endif
  29. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  30. }
  31.  
  32. void solve(){
  33. int n,k,maxi=INT_MIN;
  34. cin>>n>>k;
  35. vector<int>v(n),ans;
  36. cin(v);
  37. ans.push_back(v[0]);
  38. for(int i=1;i<n;i++){
  39. if(v[i]!=ans.back()){
  40. ans.push_back(v[i]);
  41. }else{
  42. int size=ans.size();
  43. maxi=max(maxi,size);
  44. ans.clear();
  45. ans.push_back(v[i]);
  46. }
  47. }
  48. if(maxi>=k){
  49. cout<<k<<"\n";
  50. }else{
  51. cout<<maxi<<"\n";
  52. }
  53. }
  54.  
  55. int main(){
  56. Rofyda_Elghadban();
  57. int t=1;
  58. // cin>>t;
  59. while(t--){
  60. solve();
  61. }
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement