P9412 「NnOI R1-T1」购物
· 阅读需 1 分钟
解题思路
分类讨论:
- 如果 ,显然无解。
- 如果 ,因为题目保证 ,如果 ,支付 元和 元都需要 枚硬币,所以无解。
- 如果 ,如果 ,类似第二种情况,答案不能为 ,所以答案最小为 。
- 否则, 一定大于 ,所以答案最小为 。
参考代码
#include <bits/stdc++.h>
using namespace std;
const int N=15;
int a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
cout<<(n==1||(n==2&&a[2]==2)?-1:n>2&&a[2]==2?a[3]:a[2])<<'\n';
return 0;
}