Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,k,c,x,y,maxx,maxnum,l;
  4. unordered_map<int,map<int,int>>m;
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. cin>>k>>n>>x;
  10. for(int i=2; i<=n; i++)
  11. {
  12. cin>>y;
  13. if(x==y)
  14. l++;
  15. else
  16. {
  17. m[x][l]++;
  18. x=y;
  19. l=1;
  20. }
  21. }
  22. m[x][l]++;
  23. for(auto i:m)
  24. {
  25. x=k;
  26. y=0;
  27. for(map<int,int>::reverse_iterator it=i.second.rbegin(); x>0 && it!=i.second.rend(); it++)
  28. while(it->second-- && x>0)
  29. {
  30. y+=it->first;
  31. x--;
  32. }
  33. if(y>maxx)
  34. {
  35. maxx=y;
  36. maxnum=i.first;
  37. }
  38. else if(y==maxx && i.first>maxnum)
  39. maxnum=i.first;
  40. }
  41. cin>>c;
  42. if(c==1)
  43. cout<<maxx;
  44. else
  45. cout<<maxnum;
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement