Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals), problem: (E) Cards Sorting Solution in C/C++

#include <bits/stdc++.h>
using namespace std;
set<int> s[100005];
int main()
{
int n,i,x;
cin>>n;
int m=0;
for(i=0;i<n;i++)
{
cin>>x;
s[x].insert(i);
m=max(m,x);
}
i=0;
long long int c=0,val=1,ans=0;
while(i<=m)
{
if(s[i].size()==0)
i++;
else
{
set<int>::iterator itr=s[i].lower_bound(c);
if(itr!=s[i].end())
{
c=*itr;
ans+=val;
s[i].erase(itr);
}
else
{
c=0;
val++;
}
}
}
cout<<ans<<endl;
return 0;
}

(Visited 26 times, 1 visits today)
By |2017-07-24T17:48:33+00:00July 24th, 2017|Categories: Uncategorized|0 Comments

About the Author:

Leave A Comment