#include #define ll long long #define mp make_pair #define pb push_back #define ff first #define ss second #define INF 1e17 using namespace std; const int mod=1e9+7; inline int read_int() { bool minus=false; int result=0; char ch; ch=getchar(); while(true){ if(ch=='-') break; if(ch>='0' && ch<='9') break; ch=getchar(); } if(ch=='-') minus=true; else result=ch-'0'; while(true){ ch=getchar(); if(ch<'0' || ch>'9') break; result=result*10+(ch-'0'); } if(minus) return (-result); else return result; } int T,x,k,N,M,OfferCompany,countCandidates,CompaniesNotAbleToHireCandidate; ll ans,Money; char qualified[1010][1010]; bool CompanyCandidate[1010]; pair company[1010]; int require[1010]; int main() { T=read_int(); while(T--) { Money=CompaniesNotAbleToHireCandidate=countCandidates=0; memset(CompanyCandidate,0,sizeof CompanyCandidate); N=read_int(); M=read_int(); for(int i=0;i=require[i]) { //finding maximum a candidate could get if(company[j].ff>ans) { ans=company[j].ff; OfferCompany=j; } } } if(OfferCompany==-1)//If no company is able to meet the requirements continue; countCandidates++; Money+=ans; company[OfferCompany].ss--; CompanyCandidate[OfferCompany]=true; } //counting number of companies that are not able to hire single candidate for(int i=0;i