Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n,k,c,x,y,maxx,maxnum,l;
- unordered_map<int,map<int,int>>m;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cin>>k>>n>>x;
- for(int i=2; i<=n; i++)
- {
- cin>>y;
- if(x==y)
- l++;
- else
- {
- m[x][l]++;
- x=y;
- l=1;
- }
- }
- m[x][l]++;
- for(auto i:m)
- {
- x=k;
- y=0;
- for(map<int,int>::reverse_iterator it=i.second.rbegin(); x>0 && it!=i.second.rend(); it++)
- while(it->second-- && x>0)
- {
- y+=it->first;
- x--;
- }
- if(y>maxx)
- {
- maxx=y;
- maxnum=i.first;
- }
- else if(y==maxx && i.first>maxnum)
- maxnum=i.first;
- }
- cin>>c;
- if(c==1)
- cout<<maxx;
- else
- cout<<maxnum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement