https://www.luogu.com.cn/problem/P1093
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include <map>
#include <vector>
typedef long long LL;
using namespace std;
int read(){
int x = 0,f = 1;
char c = getchar();
while (c<'0'||c>'9') {
if (c=='-') {
f = -1;
}
c = getchar();
}
while (c>='0'&&c<='9') {
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
struct info{
int ch = 0, ma = 0, en = 0;
int su = 0;
void Sum(){
su = ch+ma+en;
}
};
bool cmp(pair<int,info> a, pair<int,info> b) {
if (a.second.su > b.second.su) {
return true;
}else if(a.second.su == b.second.su){
//return a.second.ch > b.second.ch;
if(a.second.ch > b.second.ch){
return true;
}else if (a.second.ch == b.second.ch){
return a.first > b.first;
}
return false;
}
return false;
}
vector< pair<int,info> > vec;
map<int,info> student;
int main()
{
int n = read();
for(int i = 1; i<=n ; i++){
info in;
in.ch = read();
in.ma = read();
in.en = read();
in.Sum();
student[i] = in;
}
for(map<int,info>::iterator it = student.begin(); it != student.end(); it++){
vec.push_back(
pair<int,info>(it->first,it->second)
);
}
sort(vec.begin(),vec.end(),cmp);
int i = 0;
for (vector<pair<int,info> >::iterator it=vec.begin();it!=vec.end();++it){
if(i==5){
break;
}
cout<<it->first<<' '<<it->second.su<<endl;
i++;
}
return 0;
}
/*
6
91 67 80
78 89 98
78 89 91
88 99 77
67 89 64
90 66 82
============
6 265
4 264
3 258
2 244
1 237
*/
网友评论