A11637 | Friends Meeting
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Two friends are on the coordinate axis $Ox$ in points with integer coordinates. One of them is in the point $x_{1}=a$ , another one is in the point $x_{2}=b$ .
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by $1$ , the second move increases the tiredness by $2$ , the third — by $3$ and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to $1+2+3=6$ .
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by $1$ , the second move increases the tiredness by $2$ , the third — by $3$ and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to $1+2+3=6$ .
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
输入格式
The first line contains a single integer $a$ ( $1<=a<=1000$ ) — the initial position of the first friend.
The second line contains a single integer $b$ ( $1<=b<=1000$ ) — the initial position of the second friend.
It is guaranteed that $a≠b$ .
The second line contains a single integer $b$ ( $1<=b<=1000$ ) — the initial position of the second friend.
It is guaranteed that $a≠b$ .
输出格式
Print the minimum possible total tiredness if the friends meet in the same point.
输入输出样例
输入 #1
3 4
输出 #1
1
输入 #2
101 99
输出 #2
2
输入 #3
5 10
输出 #3
9
In the first example the first friend should move by one to the right (then the meeting happens at point $4$ ), or the second friend should move by one to the left (then the meeting happens at point $3$ ). In both cases, the total tiredness becomes $1$ .
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point $100$ , and the total tiredness becomes $1+1=2$ .
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point $8$ , and the total tiredness becomes $1+2+3+1+2=9$ .
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point $100$ , and the total tiredness becomes $1+1=2$ .
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point $8$ , and the total tiredness becomes $1+2+3+1+2=9$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted