SHARE
TWEET

platoukv2

a guest Feb 29th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,k,maxx,a[10005][105],l,x,y,smax=-1,elem=-1,s,C;
  4. void proces(int nr)
  5. {
  6. int aux=a[nr][a[nr][0]];
  7. int j=a[nr][0]-1;
  8. while(aux>a[nr][j] && j)
  9. a[nr][j+1] = a[nr][j],j--;
  10. a[nr][j+1]=aux;
  11. while(a[nr][0]>k)
  12. a[nr][0]--;
  13. }
  14. int main()
  15. {
  16. cin>>k>>n>>x;
  17. maxx=x;
  18. for(int i=2;i<=n;i++)
  19. {
  20. cin>>y;
  21. maxx=max(maxx,y);
  22. if(x==y) l++;
  23. else
  24. {
  25. a[x][0]++;
  26. a[x][a[x][0]]=l;
  27. proces(x);
  28. l=1;
  29. }
  30. x=y;
  31. }
  32. a[x][0]++;
  33. a[x][a[x][0]]=l;
  34. proces(x);
  35. for(int i=0;i<=maxx;i++)
  36. {
  37. s=0;
  38. for(int j=1;j<=a[i][0];j++) s+=a[i][j];
  39. if (s>=smax) smax=s,elem=i;
  40. }
  41. cin>>C;
  42. if(C==1) cout<<smax;
  43. else cout<<elem;
  44. return 0;
  45.  
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top