ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1126. Magnetic Storms

Why Memory Limit Exceeded?
Posted by Grigor 18 Jul 2005 00:03
can't figure out how this code exceeds memory limit.
    queue<int> Q;
    multiset<int, greater<int> > S;
    for (int i = 0; i < M; ++i)
    {
        int temp;
        cin >> temp;
        Q.push(temp);
        S.insert(temp);
    }
    while (true)
    {
        cout << *(S.begin()) << endl;

        int toRemove = Q.front();
        Q.pop();
        S.erase(S.find(toRemove));

        int temp;
        cin >> temp;
        if (temp == -1) break;
        Q.push(temp);
        S.insert(temp);
    }