I have written the below code using string class and have gotten TLE whereas after using char,the code was accepted.Why is it so?
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long int ll;
/*int low(stack<int> &s1)
{
int best=s1.top();
stack<int> s2 = s1;
while(!s2.empty())
{
best= min(best,s2.top());
s2.pop();
}
return best;
}*/
int main()
{
//ios::sync_with_stdio(0);
//cin.tie(0);
int n;
//cin>>n;
//cin.ignore();
scanf("%d",&n);
stack<int> s1;
//stack<int> s2;
multiset<int> m;
while(n--)
{
char s[20];
scanf("%s",s);
if (s[1] == 'U')
{
//auto it =s.find(" ");
//string part = s.substr(it+1);
//cout<<part<<endl;
int num ;//= stoi(part);
scanf("%d",&num);
s1.push(num);
m.insert(num);
}
else if (s[0] == 'M')
{
if (s1.empty())
{
//cout<<"EMPTY"<<endl;
printf("EMPTY\n");
}
else
{
//cout<<*m.begin()<<endl;
printf("%d\n",*m.begin());
}
}
else
{
if (s1.empty())
{
//cout<<"EMPTY"<<endl;
printf("EMPTY\n");
}
else
{
/*if (!s2.empty() && s1.top() == s2.top())
{
s1.pop();
s2.pop();
}
else
{
s1.pop();
}*/
auto it=m.find(s1.top());
m.erase(it);
s1.pop();
}
}
}
return 0;
}