Codeforces 246B-Increase and Decrease【模拟】

以你之姓@ 2022-08-21 13:42 129阅读 0赞

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, …, 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.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, …, a**n(|a**i| ≤ 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

  1. 2
  2. 2 1

output

  1. 1

input

  1. 3
  2. 1 4 1

output

  1. 3

解题思路:

题目大意就是在这一串数中,我们要使他们通过割补的方法,让他们高度尽可能相等的数量多,一想就知道要不是n 就是 n-1.

  1. #include<stdio.h>
  2. int num[100000];
  3. int main()
  4. {
  5. int n,ans=0;
  6. scanf("%d",&n);
  7. for(int i=0;i<n;i++)
  8. {
  9. int a;
  10. scanf("%d",&a);
  11. ans+=a;
  12. }
  13. int sum=0;
  14. if(ans%n==0)
  15. {
  16. sum=n;
  17. }
  18. else
  19. sum=n-1;
  20. printf("%d\n",sum);
  21. return 0;
  22. }

发表评论

表情:
评论列表 (有 0 条评论,129人围观)

还没有评论,来说两句吧...

相关阅读