10分,求解
查看原帖
10分,求解
1156938
Leo123123楼主2024/8/1 18:21
#include<bits/stdc++.h>
using namespace std;
int n,m;
struct node{
	int name;
	int fenshu;
}a[5005];
bool cmp(node x,node y){
	if(x.fenshu!=y.fenshu){
		return x.fenshu>y.fenshu;
	}
	if(x.fenshu==y.fenshu){
		return x.name<y.name;
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i].name>>a[i].fenshu;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=m;i++){
		if(a[i].fenshu==a[i+1].fenshu){
			m++;
			i+=2;
		}
	}
	cout<<a[m].fenshu<<" "<<m<<"\n";
	for(int i=1;i<=m;i++){
		cout<<a[i].name<<" "<<a[i].fenshu<<"\n";
	}
	return 0;
}
2024/8/1 18:21
加载中...