4
pair<int, int> currentStock = {-1, -1};9
void update(int timestamp, int price) {10
// Update current stock price if we get a new greater timestamp11
if (timestamp >= currentStock.first) {12
currentStock = {timestamp, price};15
if (stock.find(timestamp) != stock.end()) {17
int old_price = stock[timestamp]; // Get old price for timestamp19
prices[old_price]--; // Reduce count20
if (prices[old_price] == 0) prices.erase(old_price); // Remove if no timestamp has old price25
stocks[timestamp] = price;29
return currentStock.second;33
return prices.rbegin()->first; // GET last element37
return prices.begin()->first; // Get first element