B - Better Students Are Needed! Editorial by hyman0


you can use a pair<pair<int,int>,int> to store a student’s scores and number. so you can use sort(a.begin(),a.end(),cmp)to sort the array and use the function cmp to compare two elements.

#define SC pair<pair<int,int>,int>
bool cmp1(SC a,SC b){
	if(a.F.F!=b.F.F)re a.F.F>b.F.F;
	re a.S<b.S;
}
bool cmp2(SC a,SC b){
	if(a.F.S!=b.F.S)re a.F.S>b.F.S;
	re a.S<b.S;
}
bool cmp3(SC a,SC b){
	if(a.F.F+a.F.S!=b.F.F+b.F.S)re a.F.F+a.F.S>b.F.F+b.F.S;
	re a.S<b.S;
}
bool cmp4(SC a,SC b){
	re a.S<b.S;
}

we use cmp1 to select X examinees with the highest math scores, cmp2 to select Y examinees with the highest English scores, cmp3 to select Z examinees with the highest total scores in math and English,cmp4 to sort all the selected examinees with numbers.

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define elif else if
using namespace std;
const int MOD=1000000007,INF=1000000000000000000;
template<typename T>inline void Mx(T &a,T b){a=max(a,b);}
template<typename T>inline void Mi(T &a,T b){a=min(a,b);}
inline int ad(int &a,int b,int c=MOD){re a=(a+b)%c;}
template<typename T>inline T read(){T a;cin>>a;re a;}
inline bool is_digit(int msk,int d){re (msk>>d)&1;}
const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
#define SC pair<pii,int>
bool cmp1(SC a,SC b){
	if(a.F.F!=b.F.F)re a.F.F>b.F.F;
	re a.S<b.S;
}
bool cmp2(SC a,SC b){
	if(a.F.S!=b.F.S)re a.F.S>b.F.S;
	re a.S<b.S;
}
bool cmp3(SC a,SC b){
	if(a.F.F+a.F.S!=b.F.F+b.F.S)re a.F.F+a.F.S>b.F.F+b.F.S;
	re a.S<b.S;
}
bool cmp4(SC a,SC b){
	re a.S<b.S;
}
void run(){
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	vector<SC>v(n);
	rep(i,n)cin>>v[i].F.F;
	rep(i,n)cin>>v[i].F.S;
	rep(i,n)v[i].S=i;
	sort(v.begin(),v.end(),cmp1);
	sort(v.begin()+a,v.end(),cmp2);
	sort(v.begin()+a+b,v.end(),cmp3);
	//rep(i,n)cout<<v[i].S<<"\n";
	sort(v.begin(),v.begin()+a+b+c,cmp4);
	rep(i,a+b+c)cout<<v[i].S+1<<"\n";
}
signed main()
{
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
//	for(int tc=read<int>();tc;tc--)
		run();
	re 0;
}

posted:
last update: