A16072 | Ambitious Kid
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Chaneka, Pak Chanek's child, is an ambitious kid, so Pak Chanek gives her the following problem to test her ambition.
Given an array of integers $[A_1, A_2, A_3, \ldots, A_N]$ . In one operation, Chaneka can choose one element, then increase or decrease the element's value by $1$ . Chaneka can do that operation multiple times, even for different elements.
What is the minimum number of operations that must be done to make it such that $A_1 \times A_2 \times A_3 \times \ldots \times A_N = 0$ ?
Given an array of integers $[A_1, A_2, A_3, \ldots, A_N]$ . In one operation, Chaneka can choose one element, then increase or decrease the element's value by $1$ . Chaneka can do that operation multiple times, even for different elements.
What is the minimum number of operations that must be done to make it such that $A_1 \times A_2 \times A_3 \times \ldots \times A_N = 0$ ?
输入格式
The first line contains a single integer $N$ ( $1 \leq N \leq 10^5$ ).
The second line contains $N$ integers $A_1, A_2, A_3, \ldots, A_N$ ( $-10^5 \leq A_i \leq 10^5$ ).
The second line contains $N$ integers $A_1, A_2, A_3, \ldots, A_N$ ( $-10^5 \leq A_i \leq 10^5$ ).
输出格式
An integer representing the minimum number of operations that must be done to make it such that $A_1 \times A_2 \times A_3 \times \ldots \times A_N = 0$ .
输入输出样例
输入 #1
3 2 -6 5
输出 #1
2
输入 #2
1 -3
输出 #2
3
输入 #3
5 0 -1 0 1 0
输出 #3
0
In the first example, initially, $A_1\times A_2\times A_3=2\times(-6)\times5=-60$ . Chaneka can do the following sequence of operations:
1. Decrease the value of $A_1$ by $1$ . Then, $A_1\times A_2\times A_3=1\times(-6)\times5=-30$
2. Decrease the value of $A_1$ by $1$ . Then, $A_1\times A_2\times A_3=0\times(-6)\times5=0$
In the third example, Chaneka does not have to do any operations, because from the start, it already holds that $A_1\times A_2\times A_3\times A_4\times A_5=0\times(-1)\times0\times1\times0=0$
1. Decrease the value of $A_1$ by $1$ . Then, $A_1\times A_2\times A_3=1\times(-6)\times5=-30$
2. Decrease the value of $A_1$ by $1$ . Then, $A_1\times A_2\times A_3=0\times(-6)\times5=0$
In the third example, Chaneka does not have to do any operations, because from the start, it already holds that $A_1\times A_2\times A_3\times A_4\times A_5=0\times(-1)\times0\times1\times0=0$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted