列表

详情


NC244829. Make it Equal

描述

BaiQian has n numbers. She can choose any of the operating parameters . After selecting the value of k, it cannot be changed. Then BaiQian can perform an unlimited number of operations (at least once). Each operation is to select the k numbers with different positions from the n numbers and make them decrease by 1. She wants to make all the numbers equal.

How much k can BaiQian choose? If there are multiple possible k, please output the largest one.

输入描述

The first line contains one integers n . As described in the statement . 

Then the second line contains n integers a_1,a_2,...,a_n .

输出描述

Output an integer in a single line , indicates the answer.

示例1

输入:

3
5 4 4

输出:

2

示例2

输入:

4
10 10 10 1

输出:

3

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(g++ 7.5.0) 解法, 执行用时: 40ms, 内存消耗: 672K, 提交时间: 2023-05-10 20:40:08

#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	int t=0,a,b;
	cin>>a;
	for(int i=2;i<=n;i++){
		cin>>b;
		if(b!=a)t=1;
	}
	if(t==1)cout<<n-1;
	else cout<<n;
} 

C++(clang++ 11.0.1) 解法, 执行用时: 18ms, 内存消耗: 408K, 提交时间: 2022-10-22 13:37:57

#include<cstdio>
int n,x;
bool flag=1;int b;
int main()
{
	scanf("%d",&n);scanf("%d",&b);
	for(int i=2;i<=n;i++)scanf("%d",&x),flag&=x==b;
	printf("%d\n",flag?n:n-1);
}

pypy3 解法, 执行用时: 130ms, 内存消耗: 36288K, 提交时间: 2023-05-18 18:48:20

n = int(input())
s = set(list(map(int, input().split())))
print(n if len(s) == 1 else n - 1)

Python3 解法, 执行用时: 70ms, 内存消耗: 19172K, 提交时间: 2022-10-24 23:36:56

n=input()
print(n if len(set(input().split()))==1else int(n)-1)

上一题