欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1206B.Make Product Equal One
Make Product Equal One
You are given numbers . With a cost of one coin you can perform the following operation:
Choose one of these numbers and add or subtract from it.
In particular, we can apply this operation to the same number several times.
We want to make the product of all these numbers equal to , in other words, we want .
For example, for and numbers we can make product equal to in coins: add to second element, add to second element again, subtract from third element, so that array becomes . And .
What is the minimum cost we will have to pay to do that?
Input
The first line contains a single integer () — the number of numbers.
The second line contains integers () — the numbers.
Output
Output a single number — the minimal number of coins you need to pay to make the product equal to .
Note
In the first example, you can change to or to in coins.
In the second example, you have to apply at least operations for the product not to be .
In the third example, you can change to in coins, to in coins, to in coins, to in coins, to in coin.
Samples
2
-1 1
2
4
0 0 0 0
4
5
-5 -3 5 3 0
13
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |