Hi , i wrote the solution code for Cooling Pies question at :
The code seems to be fine and is working for given test cases , But it’s giving a runtime error. Im compiling the code for C++(gcc-4.3.2). The code is as follows :
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int t,temp;
int count=0;
cin>>t;
vector<int> pies;
vector<int> racks;
for(int i=0; i<t; i++)
{
int n;
cin>>n;
for(int i2=0; i2<n; i2++)
{
cin>>temp;
pies.push_back(temp);
}
for(int i2=0; i2<n; i2++)
{
cin>>temp;
racks.push_back(temp);
}
sort(pies.begin(),pies.end());
sort(racks.begin(),racks.end());
count=0;
while(racks.size()>0)
{
while(pies.at(0)>racks.at(0))
racks.erase(racks.begin());
if(racks.size()>0)
{
pies.erase(pies.begin());
racks.erase(racks.begin());
}
else break;
count++;
}
pies.clear();
racks.clear();
cout<<count<<endl;
}
return 0;
}
Thanks.