A1187 | [COCI-2010_2011-contest1]#1 LJUTNJA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Children in a kindergarten have received a large sack containing M candies. It has been decided that the candies are to be distributed among N children.
Each child has stated the number of candies that it wants. If a child isn’t given the amount of candy it wants, it will get angry. In fact it’ll get angrier for each candy it is deprived of. Some speculate that it’s anger will be equal to the square of the number of candy it is deprived of. For instance, if Mirko states that he wants 32 candies but receives only 29, he would be missing 3 candies, so his anger would be equal to
9.
Unfortunately, there is an insufficient amount of candy to satisfy all children. Therefore, the candies should be distributed in such a way that the sum of the children’s anger is minimal.
Each child has stated the number of candies that it wants. If a child isn’t given the amount of candy it wants, it will get angry. In fact it’ll get angrier for each candy it is deprived of. Some speculate that it’s anger will be equal to the square of the number of candy it is deprived of. For instance, if Mirko states that he wants 32 candies but receives only 29, he would be missing 3 candies, so his anger would be equal to
9.
Unfortunately, there is an insufficient amount of candy to satisfy all children. Therefore, the candies should be distributed in such a way that the sum of the children’s anger is minimal.
输入格式
The first line contains two integers, M (1 ≤ M ≤ 2·109) and N (1 ≤ N ≤ 100 000).
The following N lines contain integers (one per line) which represent the wishes of the children. Those numbers are all strictly less than 2·109, and their sum always exceeds M.
The following N lines contain integers (one per line) which represent the wishes of the children. Those numbers are all strictly less than 2·109, and their sum always exceeds M.
输出格式
e first and only line of output must contain the minimum sum of the children’s anger.
Note: The test cases will ensure that the result fits in a 64-bit unsigned integer: int64 in Pascal, long long in C/C++, long in Java.
Note: The test cases will ensure that the result fits in a 64-bit unsigned integer: int64 in Pascal, long long in C/C++, long in Java.
输入输出样例
输入 #1
5 3 1 3 2
输出 #1
1
输入 #2
10 4 4 5 2 3
输出 #2
4
Test cases worth 40% of total points have M not greater than 200 000.
Test cases worth 70% of total points have no child state that it wants more than 100 000 candies.
Test cases worth 80% of total points have at least one of the above stated constraints will be met.
Test cases worth 70% of total points have no child state that it wants more than 100 000 candies.
Test cases worth 80% of total points have at least one of the above stated constraints will be met.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted