C++ beats 100%
Used two maps for each of the buys and sells; and using the iterator pointers, I would decrement the necessary map values.\n\nclass Solution {\npublic:\n    int
Used two maps for each of the buys and sells; and using the iterator pointers, I would decrement the necessary map values.\n```\nclass Solution {\npublic:\n    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n        map<int,long> mpBuy;\n        map<int,long> mpSell;\n        int count = 0;\n        for (int i = 0;i<orders.size();i++){\n            if (orders[i][2]==0 && mpBuy.find(orders[i][0])!=mpBuy.end()){\n                mpBuy[orders[i][0]] += orders[i][1];\n                continue;\n            }\n            if (orders[i][2]==1 && mpSell.find(orders[i][0])!=mpSell.end()){\n                mpSell[orders[i][0]] += orders[i][1];\n                continue;\n            }\n            if (orders[i][2]==0){\n                if (mpSell.size()==0){\n                    mpBuy[orders[i][0]] += orders[i][1];\n                    continue;\n                }\n                auto it = mpSell.begin();\n                count = orders[i][1];\n                while(count>0){\n                    if ((*it).first<=orders[i][0] && (*it).second>count){\n                        (*it).second -= count;\n                        count = 0;\n                        break;\n                    }\n                    if ((*it).first<=orders[i][0] && (*it).second<=count){\n                        count -= (*it).second;\n                        auto it2 = it;\n                        it++;\n                        mpSell.erase((*it2).first);\n                    }\n                    if (mpSell.size()==0){\n                        break;\n                    }\n                    if ((*it).first>orders[i][0]){\n                        break;\n                    }\n                }\n                if (count!=0){\n                    mpBuy[orders[i][0]] += count;\n                }\n                continue;\n            }\n            if (orders[i][2]==1){\n                if (mpBuy.size()==0){\n                    mpSell[orders[i][0]] += orders[i][1];\n                    continue;\n                }\n                auto it = mpBuy.end();\n                it--;\n                count = orders[i][1];\n                while(count>0){\n                    if ((*it).first>=orders[i][0] && (*it).second>count){\n                        (*it).second -= count;\n                        count = 0;\n                        break;\n                    }\n                    if ((*it).first>=orders[i][0] && (*it).second<=count){\n                        count -= (*it).second;\n                        auto it2 = it;\n                        it--;\n                        mpBuy.erase((*it2).first);\n                    }\n                    if (mpBuy.size()==0){\n                        break;\n                    }\n                    if ((*it).first<orders[i][0]){\n                        break;\n                    }\n                }\n                if (count!=0){\n                    mpSell[orders[i][0]] += count;\n                }\n                continue;\n            }\n        }\n        long sum = 0;\n        for (auto it = mpBuy.begin();it!=mpBuy.end();++it){\n            sum += (*it).second;\n        }\n        for (auto it = mpSell.begin();it!=mpSell.end();++it){\n            sum += (*it).second;\n        }\n        sum %= (int)1e9+7;\n        return sum;\n    }\n};\n```
[]