https://i0.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Codeforces-Round-424-Div-2-rated-based-on-VK-Cup-Finals-problem-E-Cards-Sorting-Solution-in-CC1.png?fit=640%2C360

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 5 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: