P5682 [CSP-J2019 江西] 次大值 70分
  • 板块灌水区
  • 楼主wyc14
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/10/4 19:15
  • 上次更新2024/10/4 21:06:20
查看原帖
P5682 [CSP-J2019 江西] 次大值 70分
741524
wyc14楼主2024/10/4 19:15
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int MAXM = 1e9 + 5;
int n, a[MAXN], b[MAXN], cnt, c[MAXN];
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			if(i == j) continue;
			int x = a[i] % a[j];
			if(b[x] == 0)
			{
				b[x] = 1;
				cnt++;
				c[cnt] = x;
			}
		}
	}
	if(cnt < 2)
	{
		cout << -1;
		return 0;
	}
	sort(c + 1, c + cnt + 1);
	cout << c[cnt - 1];
	return 0;
}
2024/10/4 19:15
加载中...