CF246B.Increase and Decrease
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarpus has an array, consisting of n integers _a_1, _a_2, ..., a__n. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array a__i, a__j (i ≠ j);
- he simultaneously increases number a__i by 1 and decreases number a__j by 1, that is, executes a__i = a__i + 1 and a__j = a__j - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Polycarpus 有一个由 n 个整数 a1,a2,…,an 组成的数组。Polycarpus 喜欢数组中数字相等的情形,因此他希望数组中相等的数字尽可能多。为此,他可以多次执行如下操作:
- 他选择数组中的两个元素 ai、aj(其中 i=j);
- 同时将 ai 增加 1、将 aj 减少 1,即执行 ai=ai+1 和 aj=aj−1。
该操作每次恰好改变两个不同的数组元素。Polycarpus 可以无限次地执行上述操作。
现在他想知道:在执行任意次数的此类操作后,数组中最多能有多少个相等的元素?请帮助 Polycarpus。
输入格式
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers _a_1, _a_2, ..., a__n (|a__i| ≤ 104) — the original array.
第一行包含一个整数 n(1≤n≤105)—— 数组的大小。
第二行包含 n 个以空格分隔的整数 a1,a2,…,an(∣ai∣≤104)—— 原始数组。
输出格式
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
输出一个整数——在执行任意次数给定操作后,他能得到的相等数组元素的最大个数。
输入输出样例
输入#1
2 2 1
输出#1
1
输入#2
3 1 4 1
输出#2
3
输入解题思路,AI测评打分。不知道怎么写?