「NnOI」Round 1 购物 官方题解
出题人题解。
由于
首先,发现无解情况共有两个:
否则,如果
如果
综上,答案如下:
//By: OIer rui_er
#include <bits/stdc++.h>
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define debug(format...) fprintf(stderr, format)
#define fileIO(s) do{freopen(s".in","r",stdin);freopen(s".out","w",stdout);}while(false)
using namespace std;
typedef long long ll;
mt19937 rnd(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
int randint(int L, int R) {
uniform_int_distribution<int> dist(L, R);
return dist(rnd);
}
template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}
const int N = 15;
int n, a[N];
int main() {
scanf("%d", &n);
rep(i, 1, n) scanf("%d", &a[i]);
if(n == 1) puts("-1");
else if(n == 2 && a[2] == 2) puts("-1");
else if(a[2] == 2) printf("%d\n", a[3]);
else printf("%d\n", a[2]);
return 0;
}