My code for implementation says terminated due to timeout

#include
#include
#include
using namespace std;

class Stack {
private:
vector v;
public:
void push(int data) {
v.push_back(data);
}
bool empty() {
return v.size()==0;
}
void pop() {
if(!empty()) {
v.pop_back();
}
}
int max() {
return *max_element(v.begin(),v.end());
}
};

int main() {
int n; cin>>n;
Stack s;
for(int i=0; i<n; i++) {
int k,max1=0,max2=0; cin>>k;
if(k==1) {
int x; cin>>x;
s.push(x);
}
if(k==2) {
s.pop();
}
if(k==3) {
cout<<s.max()<<"\n";
}
}
}

reply.
plese help???

Please save your code on ide.codingblocks.com and then share its link.

i dont know how to share link of ide

Paste you code on ide.codingblocks.com .Then click on the save button. After that copy the URL of that page and paste it here.

help.

Your code is working fine for some inputs i gave. If this is a hackerblocks/course question then please share the question name. I will check with the test cases.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.