- 学习减法II
求调
- @ 2026-1-24 17:35:38
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
vector<long long>a(n);
long long sum=0,mx=0,mn=1e9;
for(int i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
mx=max(mx,a[i]);
mn=min(mn,a[i]);
}
for (int k=n;k>=1;k--){
if (k==n) {
if(mx*n==sum) {
cout<<k;
return 0;
}
continue;
}
long long up=(sum-k*mx)/(n-k);
if (up>mn){
up=mn;
}
bool found=0;
for (long long x=up;x>=0;x--){
if((sum-n*x)%k==0){
found=1;
break;
}
}
if(found){
cout<<k;
return 0;
}
}
cout<<"1";
return 0;
}
1 条评论
-
User31 LV 9 @ 2026-1-24 17:35:48啊啊啊
👍 2❤️ 2🤔 2🤣 2😄 2😕 2🌿 2🕊️ 2
- 1
信息
- ID
- 53
- 时间
- ms
- 内存
- MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 7
- 已通过
- 2
- 上传者