Problem Link: http://acm.epoka.edu.al:8888/en/problem-pid-c7b3?ps=1&smt=9&smpwid=0
#include <bits/stdc++.h>
using namespace std;
bool comparename( const pair<string,long long int>& x, const pair<string, long long int>& y )
{
if(x.first.size()==y.first.size())
{
if(x.second==y.second)
{
return x.first<y.first;
}
return x.second<y.second;
}
return x.first.size()<y.first.size();
}
int main()
{
vector<pair<string,long long int> >a;
set<pair<string,long long int> >myset;
vector<string>ss;
vector<long long int>gd;
long long int n,i,j,b,c,cnt=0,l,sh;
string s;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin>>n>>sh;
for(i=1;i<=n;i++)
{
cin>>s>>c;
a.push_back(make_pair(s,c));
}
sort(a.begin(),a.end(),comparename);
vector<pair<string,long long int> >::iterator p;
for(p=a.begin();p!=a.end();p++)
{
if(cnt==sh)
{
break;
}
cout<<p->first<<" "<<p->second<<endl;
cnt++;
}
return 0;
}
0 comments:
Post a Comment