提交时间:2022-04-10 15:57:51
运行 ID: 48191
#include <bits/stdc++.h> using namespace std; int minn,maxn,n,now,opt=1,Max,Min,f=1; vector<int>a(105,0); inline void A() { maxn=0x7ffffff; for(int i=0; i<now-1; i++) if(max(a[i],a[i+1])<maxn) maxn=max(a[i],a[i+1]),Max=a[i]>a[i+1]?i:i+1; a.erase(a.begin()+Max); } inline void B() { maxn=-1; for(int i=0; i<now-1; i++) if(min(a[i],a[i+1])>minn) minn=min(a[i],a[i+1]),Min=a[i]<a[i+1]?i:i+1; a.erase(a.begin()+Min); } void solve() { scanf("%d", &n); for(int i(0); i<n; i++) scanf("%d", &a[i]); for(int i(0); i<n; i++) if(a[i] != 0) f = 0; now = n; while(now > 1) { if(opt == 1) A(); else B(); opt == 1 ? opt = 0 : opt = 1, now--; Max = Min = 0; } if(f == 1) puts("0"); else printf("%d\n", a[0]); } int main() { // freopen("game.in","r",stdin); //freopen("game.out","w",stdout); solve(); return 0; }