Increase and Decrease
来源:互联网 发布:js tab选项卡 编辑:程序博客网 时间:2024/05/21 22:50
Increase and Decrease
时间限制:1000 ms | 内存限制:65535 KB
难度:1
- 描述
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 ai, aj (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.
- 输入
- The first line contains integer n (1 ≤ n ≤ 10^5) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 10^4) — the original array.
- 输出
- Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
- 样例输入
22 131 4 1
- 样例输出
13
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);while (scanner.hasNext()) {int number = scanner.nextInt();int sum = 0;for (int i = 0; i < number; i++) {int temp = scanner.nextInt();sum += temp;}int result = 0;if (sum % number == 0) {result = number;} else {result = number - 1;}System.out.println(result);}}}
阅读全文
0 0
- B. Increase and Decrease
- Increase and Decrease
- Increase and Decrease
- Increase and Decrease--codeForces 246B
- CodeForces 246B: Increase and Decrease【水】
- Codeforces 246B Increase and Decrease 【数学】
- Codeforces 246B-Increase and Decrease【模拟】
- CodeForces 246BB. Increase and Decrease【思维】
- CodeForces 246B Increase and Decrease
- Codeforces 246B Increase and Decrease
- 【Codeforces 246B Increase and Decrease 】
- CF - 246 - B. Increase and Decrease(贪心)
- CodeForces - 246B Increase and Decrease (模拟)水
- Java Date decrease or increase
- CUIT ACM Personal Training 11.27(FM)G - Increase and Decrease
- Using DataReaders to Increase Speed and Reduce Memory
- jQuery:mouseover and Increase the Size of an Image
- jQuery:mouseover and Increase the Size of an Image
- DbVisualizer9.5.7编辑页面怎么设置字体编码
- [Mysql]——通过例子理解事务的4种隔离级别
- php isset()与empty()的使用 完美版
- 换行符
- 数据结构课程主页-2016级
- Increase and Decrease
- C++ 异常处理 catch(...)介绍
- HDU 6139 Galaxy at War(坑题+阶梯博弈)
- 目标检测--RON: Reverse Connection with Objectness Prior Networks for Object Detection
- 神经机器翻译中的领域自适应问题 Domain adaptation for NMT
- webmagic爬取职位信息,新手上路
- 为CheckBox设置点击样式(button属性)
- 小结
- python:单引号,双引号和三引号的区别