c++(196ms 99%) two maps
Runtime: 196 ms, faster than 98.82% of C++ online submissions for Number of Orders in the Backlog.\nMemory Usage: 64.5 MB, less than 39.53% of C++ online submis
Runtime: 196 ms, faster than 98.82% of C++ online submissions for Number of Orders in the Backlog.\nMemory Usage: 64.5 MB, less than 39.53% of C++ online submissions for Number of Orders in the Backlog.\n```\nclass Solution {\npublic:\n  int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n    map<int, long> buy, sell;\n    \n    for(auto &it: orders) \n      if(it[2]){                                             //buy\n        auto b = buy.rbegin();\n        while(b != buy.rend() && it[0] <= b->first){         //if we can buy\n          it[1] -= b->second;\n          if(it[1] <  0) {b->second = -it[1]; break;}\n          \n          int tmp = b->first; \n          b++;                                          \n          buy.erase(tmp);\n          if(it[1] == 0) break;\n        }\n        if(it[1] > 0) sell[it[0]] += it[1];\n      }\n      else {                                                 //sell\n        auto s = sell.begin();\n        while(s != sell.end() && it[0] >= s->first){         //if we can sell\n          it[1] -= s->second;\n          if(it[1] <  0) {s->second = -it[1]; break;}\n          \n          int tmp = s->first;\n          s++;\n          sell.erase(tmp);\n          if(it[1] == 0) break;\n        }\n        if(it[1] > 0) buy[it[0]] += it[1];\n      } \n      \n    \n    long answer = 0;\n    for(auto &it: buy ) answer += it.second;\n    for(auto &it: sell) answer += it.second;\n    \n    return answer % 1000000007;\n  }\n};\n```
['C', 'C++']