A9467 | Physical Education and Buns
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The Physical education teacher at SESC is a sort of mathematician too. His most favorite topic in mathematics is progressions. That is why the teacher wants the students lined up in non-decreasing height form an arithmetic progression.
To achieve the goal, the gym teacher ordered a lot of magical buns from the dining room. The magic buns come in two types: when a student eats one magic bun of the first type, his height increases by one, when the student eats one magical bun of the second type, his height decreases by one. The physical education teacher, as expected, cares about the health of his students, so he does not want them to eat a lot of buns. More precisely, he wants the maximum number of buns eaten by some student to be minimum.
Help the teacher, get the maximum number of buns that some pupils will have to eat to achieve the goal of the teacher. Also, get one of the possible ways for achieving the objective, namely, the height of the lowest student in the end and the step of the resulting progression.
To achieve the goal, the gym teacher ordered a lot of magical buns from the dining room. The magic buns come in two types: when a student eats one magic bun of the first type, his height increases by one, when the student eats one magical bun of the second type, his height decreases by one. The physical education teacher, as expected, cares about the health of his students, so he does not want them to eat a lot of buns. More precisely, he wants the maximum number of buns eaten by some student to be minimum.
Help the teacher, get the maximum number of buns that some pupils will have to eat to achieve the goal of the teacher. Also, get one of the possible ways for achieving the objective, namely, the height of the lowest student in the end and the step of the resulting progression.
输入格式
The single line contains integer $n$ ( $2<=n<=10^{3}$ ) — the number of students. The second line contains $n$ space-separated integers — the heights of all students. The height of one student is an integer which absolute value doesn't exceed $10^{4}$ .
输出格式
In the first line print the maximum number of buns eaten by some student to achieve the teacher's aim. In the second line, print two space-separated integers — the height of the lowest student in the end and the step of the progression. Please, pay attention that the step should be non-negative.
If there are multiple possible answers, you can print any of them.
If there are multiple possible answers, you can print any of them.
输入输出样例
输入 #1
5 -3 -4 -2 -3 3
输出 #1
2 -3 1
输入 #2
5 2 -3 -1 -4 3
输出 #2
1 -4 2
Lets look at the first sample. We can proceed in the following manner:
- don't feed the 1-st student, his height will stay equal to -3;
- give two buns of the first type to the 2-nd student, his height become equal to -2;
- give two buns of the first type to the 3-rd student, his height become equal to 0;
- give two buns of the first type to the 4-th student, his height become equal to -1;
- give two buns of the second type to the 5-th student, his height become equal to 1.
To sum it up, when the students line up in non-decreasing height it will be an arithmetic progression: -3, -2, -1, 0, 1. The height of the lowest student is equal to -3, the step of the progression is equal to 1. The maximum number of buns eaten by one student is equal to 2.
- don't feed the 1-st student, his height will stay equal to -3;
- give two buns of the first type to the 2-nd student, his height become equal to -2;
- give two buns of the first type to the 3-rd student, his height become equal to 0;
- give two buns of the first type to the 4-th student, his height become equal to -1;
- give two buns of the second type to the 5-th student, his height become equal to 1.
To sum it up, when the students line up in non-decreasing height it will be an arithmetic progression: -3, -2, -1, 0, 1. The height of the lowest student is equal to -3, the step of the progression is equal to 1. The maximum number of buns eaten by one student is equal to 2.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted