我在IDE中检查了我的解决方案。
但是当我要提交我的解决方案时,它会抛出错误SIGABRT
。
问题出在哪里?
使用此输入在IDE中的示例测试用例中运行良好:
1
5 6
5000 10000 3000 20 100
10000 2
800 2
600 1
10 8
1000 9
2000 10
111111
100000
000000
000001
100100
约束:
1≤T≤10,1≤NOffandidates,noOfCompanies≤10^3,0≤ minSalary [i]≤10^9,0≤qual[i] [j]≤1,1≤exmentsSalary[i]≤ 10 ^9,1≤maxJobOffers[i]≤10^ 6,数组的所有元素 offersSalary是不同的
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#define ll long long int
using namespace std;
int main()
{
int t; cin>>t;
while(t--)
{
int no_cand,no_comp;
cin>>no_cand>>no_comp;
vector<ll> minSalary(no_cand+1);
for(int i=1;i<=no_cand;++i)
cin>>minSalary[i];
vector<ll> offeredSalary(no_comp+1);
vector<ll> maxJobOffers(no_comp+1);
vector<ll> hiring(no_comp+1);
for(int i=1;i<=no_comp;++i)
{
cin>>offeredSalary[i]>>maxJobOffers[i];
hiring[i]=maxJobOffers[i];
}
string str[no_cand+1];
vector<int> qual[no_cand+1];
cin.ignore();
for(int i=1;i<=no_cand+1;++i)
{
getline(cin,str[i],'\n');
for(int j=0;j<str[i].length();++j)
{
if(str[i][j]=='1' && minSalary[i]<=offeredSalary[j+1])
qual[i].push_back(j+1);
}
}
int placed=0,un_hired=0;
ll amount =0;
for(int i=1;i<=no_cand;++i)
{
vector< pair<ll,int> > offerLetter;
for(int j=0;j<qual[i].size();++j)
{
int p=qual[i][j];
if(maxJobOffers[p]>0)
offerLetter.push_back(make_pair(offeredSalary[p],p));
}
if(offerLetter.size()==0) continue;
sort(offerLetter.begin(),offerLetter.end(),greater< pair<ll,int> >());
pair<ll,int> temp=*offerLetter.begin();
amount+=temp.first;
--maxJobOffers[temp.second];
++placed;
offerLetter.clear();
}
vector<ll>::iterator it1=maxJobOffers.begin()+1;
vector<ll>::iterator it2=hiring.begin()+1;
for( ;it1!=maxJobOffers.end() && it2!=hiring.end();++it1,++it2)
{
// cout<<*it1<<" "<<*it2<<endl;
if(*it1==*it2)
++un_hired;
}
maxJobOffers.clear();
hiring.clear();
offeredSalary.clear();
qual[no_cand+1].clear();
cout<<placed<<" "<<amount<<" "<<un_hired<<"\n";
}
return 0;
}