Problem Link: http://acm.epoka.edu.al:8888/en/problem-pid-c62e?ps=1&smt=a&smpwid=0
#include <bits/stdc++.h>
using namespace std;
bool compareamount(const pair<string,int>& x, const pair<string, int>& y )
{
return (x.second > y.second); //descending
}
bool compareid(const pair<int,int>& x, const pair<int, int>& y )
{
return (x.second > y.second); //descending
}
int main()
{
int n,m,id,i,j,k,l,v,total,cnt=0;
string pn,pc;
float ep,sp;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin>>n>>m;
vector<pair<string,int> >s;
vector<pair<int,int> >ids;
vector<int>pid;
vector<string>product;
vector<int>amount;
for(i=1;i<=n;i++)
{
cin>>id;
cin>>pn>>pc;
cin>>ep>>sp;
total=0;
for(j=1;j<=5;j++)
{
cin>>v;
total=total+v;
}
s.push_back(make_pair(pn,total));
ids.push_back(make_pair(id,total));
}
sort(s.begin(),s.end(),compareamount);
sort(ids.begin(),ids.end(),compareid);
vector<pair<string,int> >::iterator p;
vector<pair<int,int> >::iterator q;
for(q=ids.begin();q!=ids.end();q++)
{
if(cnt==m)
{
break;
}
pid.push_back(q->first);
cnt++;
}
cnt=0;
for(p=s.begin();p!=s.end();p++)
{
if(cnt==m)
{
break;
}
//cout<<p->first<<" "<<p->second<<endl;
product.push_back(p->first);
amount.push_back(p->second);
cnt++;
}
for(i=0;i<pid.size();i++)
{
cout<<pid[i]<<" "<<product[i]<<" "<<amount[i]<<endl;
}
return 0;
}
0 comments:
Post a Comment