1381.cpp (412B)
1 class CustomStack { 2 vector<int> st; 3 int size = 0; 4 5 public: 6 CustomStack(int maxSize) : st(maxSize) {} 7 8 void push(int x) { 9 if (size == st.size()) return; 10 st[size++] = x; 11 } 12 13 int pop() { 14 if (size == 0) return -1; 15 return st[--size]; 16 } 17 18 void increment(int k, int val) { 19 for (int i = 0; i < min(k, size); i++) 20 st[i] += val; 21 } 22 };