PAT A1057 STACK(30) 有没有大佬能帮我看看这道题哪里错了?只得了10分

图片说明

图片说明
图片说明

#include<cstdio>
#include<string>
#include<iostream>
#include<stack>
#include<set>
using namespace std;
int n;
int main()
{
    cin>>n;
    stack<int> s;
    multiset<int> order;
    int key;
    for(int i = 0; i < n; i++)
    {
        string ope;
        cin>>ope;
        if(ope == "Push")
        {
            cin>>key;
            s.push(key);
            order.insert(key);
        }
        else if(ope == "Pop" && !s.empty())
        {
            int val = s.top();
            cout<<val<<endl;
            s.pop();
            order.erase(val);
        }
        else if(ope == "PeekMedian")
        {
            if(order.empty())
            cout<<"Invalid"<<endl;
            else
            {
                int num = s.size();
                num = (num%2 == 0)? num/2 : (num+1)/2;
                auto it = order.begin();
                cout<<(*it+num-1)<<endl;
            }
        }
        else
        {
            cout<<"Invalid"<<endl;
        }
    }
    return 0;
 }