Codeforces 246B-Increase and Decrease【模拟】

来源:互联网 发布:女流和陈一发 知乎 编辑:程序博客网 时间:2024/05/22 00:43
B. Increase and Decrease
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarpus has an array, consisting of n integers a1, a2, ..., an. 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 aiaj (i ≠ j);
  • he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 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.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an(|ai| ≤ 104) — the original array.

Output

Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.

Examples
input
22 1
output
1
input
31 4 1
output
3
解题思路:
题目大意就是在这一串数中,我们要使他们通过割补的方法,让他们高度尽可能相等的数量多,一想就知道要不是n 就是 n-1.
#include<stdio.h>int num[100000];int main(){int n,ans=0;scanf("%d",&n);for(int i=0;i<n;i++){int a;scanf("%d",&a);ans+=a;}int sum=0;if(ans%n==0){sum=n;}elsesum=n-1;printf("%d\n",sum);return 0; } 


0 0