Time limit problem for Alien Chef.

I wrote a program for Alien chef problem today.
The concrete concept of the problem is clear, but I am wondering why I always got time exceeded.
Here are my codes, can anyone help me to solve this problem.

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std; 

int main()
{
	int num_recipes;
	long long se[5001][3];
	int group_alien;
	int k;
	long long t,count,temp; 
	int flag[5]={0};

	cin>>num_recipes;
	//cout<<"num-recipes:"<<num_recipes<<endl;
	for(int i=0;i<num_recipes;i++){
		cin>>se[i][0];
		cin>>se[i][1];
	}
	for(int i=0;i<num_recipes;i++){
		for(int j =i+1;j<num_recipes;j++){
			if(se[i][0]>se[j][0]){
				temp = se[i][0];
				se[i][0] = se[j][0];
				se[j][0] = temp;

				temp = se[i][1];
				se[i][1] = se[j][1];
				se[j][1] = temp;
				
			}
		}
	}

	/*for(int i=0;i<num_recipes;i++){
		cout<<se[i][0]<<" "<<se[i][1]<<endl;
	}*/

	cin>>group_alien;
	count =0;
	for(int i=0;i<group_alien;i++)
	{
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>t;
			for(int m=0;m<num_recipes;m++){
				if(t >= se[m][0] && t <= se[m][1] && flag[m]==0){
					//cout<<"i:"<<i<<" t:"<<t<<" se["<<m<<"][0]:"<<se[m][0]<<" se["<<m<<"][1]:"<<se[m][1]<<endl;
					count++;
					flag[m] =1;
				}
				else if( t < se[m][0]) break;
			}
		}
		cout<<count<<endl;
		count=0; 
		for(int n=0;n<num_recipes;n++){
			flag[n] =0;
		}
	}
	system("pause");
	return 0;
}

Try to remove system("pause") first :wink:

And if there is TLE still, replace cout with printf() and cin with scanf(), while cin and cout are slow.

The concrete concept of the problem is clear

I’m not so sure. MAXN is 10^5 and you have inner loop:

for(int i=0;i<num_recipes;i++){
    for(int j =i+1;j<num_recipes;j++){
        ...
    }
}

Are you sure you want to perform 10^10 operations in 3 seconds?

//