Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

@Daniel JourDaniel Jour suggested in his great answergreat answer to use a std::priority_queue. I thought I give that a try and turn it into a full working example code. It's pretty much a straightforward implementation of the problem description.

#include <iostream>
#include <queue>

int main ()
{
    int N = 0, M = 0, input = 0;
    
    std::priority_queue<int> sortedWealthList;
    
    std::cin >> N >> M;
    
    for(int inputLine = 0; inputLine < N + M; ++inputLine)
    {
        std::cin >> input;
        
        if (input == -1)
        {
            std::cout << sortedWealthList.top() << "\n";
            sortedWealthList.pop();
        }
        else
        {
            sortedWealthList.push(input);
        }
    }
}

That scores 100 on the IARCS Problems Archive, whatever that means.

@Daniel Jour suggested in his great answer to use a std::priority_queue. I thought I give that a try and turn it into a full working example code. It's pretty much a straightforward implementation of the problem description.

#include <iostream>
#include <queue>

int main ()
{
    int N = 0, M = 0, input = 0;
    
    std::priority_queue<int> sortedWealthList;
    
    std::cin >> N >> M;
    
    for(int inputLine = 0; inputLine < N + M; ++inputLine)
    {
        std::cin >> input;
        
        if (input == -1)
        {
            std::cout << sortedWealthList.top() << "\n";
            sortedWealthList.pop();
        }
        else
        {
            sortedWealthList.push(input);
        }
    }
}

That scores 100 on the IARCS Problems Archive, whatever that means.

@Daniel Jour suggested in his great answer to use a std::priority_queue. I thought I give that a try and turn it into a full working example code. It's pretty much a straightforward implementation of the problem description.

#include <iostream>
#include <queue>

int main ()
{
    int N = 0, M = 0, input = 0;
    
    std::priority_queue<int> sortedWealthList;
    
    std::cin >> N >> M;
    
    for(int inputLine = 0; inputLine < N + M; ++inputLine)
    {
        std::cin >> input;
        
        if (input == -1)
        {
            std::cout << sortedWealthList.top() << "\n";
            sortedWealthList.pop();
        }
        else
        {
            sortedWealthList.push(input);
        }
    }
}

That scores 100 on the IARCS Problems Archive, whatever that means.

Source Link

@Daniel Jour suggested in his great answer to use a std::priority_queue. I thought I give that a try and turn it into a full working example code. It's pretty much a straightforward implementation of the problem description.

#include <iostream>
#include <queue>

int main ()
{
    int N = 0, M = 0, input = 0;
    
    std::priority_queue<int> sortedWealthList;
    
    std::cin >> N >> M;
    
    for(int inputLine = 0; inputLine < N + M; ++inputLine)
    {
        std::cin >> input;
        
        if (input == -1)
        {
            std::cout << sortedWealthList.top() << "\n";
            sortedWealthList.pop();
        }
        else
        {
            sortedWealthList.push(input);
        }
    }
}

That scores 100 on the IARCS Problems Archive, whatever that means.