Let's create a stack where the minimum element of the stack can be queried in O(1) time.
We can do this by keeping a pair in the stack, with the element and the minimum in the stack starting from this element.
#include <stack>
int main() {
<pair<int, int>> st;
stack// adding an element
int new_min = std.empty() ? new_elem : min(new_elem, st.top().second);
.push({new_elem, new_min});
st// removing an element
int removed_element = st.top().first;
.pop();
st// Finding the minimum
int minimum = st.top().second;
}