//####################
//Editor
//####################
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<bool> on(n+1, false);
on[0] = true;
vector<pair<int,int>> opps;
opps.pb({0,0});
for(int i = 0 ; i < n ; i++){
int opp;cin>>opp;
on[i+1] = true;
if(opp > 0){
opps.pb({0,-opp});
}else{
int to_undo = -1;
for(int j = opps.size()-1 ; j>=0 ; j--){
if(on[j] && opps[j].first < -opp){to_undo=j;break;}
}
opps.pb({-opp, to_undo});
int act = to_undo;
while(opps[act].second > 0){
on[act] = !on[act];
act = opps[act].second;
}
if(act !=0){
on[act] = !on[act];
}
}
for(int j = opps.size()-1;j>=0;j--){
if(on[j] && opps[j].first==0){
cout << -opps[j].second << '\n';break;
}
}
}
return 0;
};
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |