Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: KurtCobain

Problemset: ประมูลการกุศล

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-03 15:23:25

#include <iostream>
#include <map>
#include <stack>
using namespace std;

int main(){
    int n;
    cin >> n;
    stack<int> prices = {};
    for (int i=0;i<n;i++){
      int x;
      cin >> x;
      if (prices.empty()){
        prices.push(x);
        continue;
      }
      if (x > prices.top()){
         prices.push(x);
      }
    }
    int ans = 0;
    while (!prices.empty()){
        ans+=prices.top();
        prices.pop();
    }
    cout << ans;
}