跳到正文

个人记录

Somebody needs it

gw2204约 2 分钟
原文

这是 2026年11月19日 存档的第 6 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2024年11月27日
收录
2025年12月12日
更新
2026年11月20日
篇幅
约 2 分钟
获赞
1

版本

  1. v7当前
  2. v6
  3. v5
  4. v4
更早的 3 个版本
  1. v3
  2. v2
  3. v1
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100010;
int n, a[N], sum, maxx, ans = -1;
signed main() {
	freopen("crossseal.in", "r", stdin);
	freopen("crossseal.out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		maxx = max(maxx, a[i]);
		sum += a[i];
	}
	for (int l = 2, r; l <= maxx; l = r + 1) {
		r = maxx;
		int now = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] >= l) r = min(r, a[i] / (a[i] / l));
			now += a[i] / l;
		}
		int wc = sum / now - 1;
		if (wc > r) break;
		if (sum % now == 0) {
			if (wc >= l && wc <= r) {
				bool bl = 1;
				for (int i = 1; i <= n; i++) {
					if (a[i] % wc > now - a[i] / wc) {
						bl = 0;
						break;
					}
				}
				if (bl) ans = max(ans, wc);
			}
		}
	}
	cout << ans;
}