- 学习减法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;
}
2 條評論
-
user2 LV 8 @ 2026-8-18 8:01:41求调
-
@ 2026-1-24 17:35:48啊啊啊
👍 2❤️ 2🤔 2🤣 2😄 2😕 2🌿 2🕊️ 2
- 1
資訊
- ID
- 53
- 時間
- ms
- 記憶體
- MiB
- 難度
- 10
- 標籤
- (無)
- 遞交數
- 7
- 已透過
- 2
- 上傳者