A8565 | Chores
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do $n$ chores. Each chore is characterized by a single parameter — its complexity. The complexity of the $i$ -th chore equals $h_{i}$ .
As Petya is older, he wants to take the chores with complexity larger than some value $x$ ( $h_{i}>x$ ) to leave to Vasya the chores with complexity less than or equal to $x$ ( $h_{i}<=x$ ). The brothers have already decided that Petya will do exactly $a$ chores and Vasya will do exactly $b$ chores ( $a+b=n$ ).
In how many ways can they choose an integer $x$ so that Petya got exactly $a$ chores and Vasya got exactly $b$ chores?
As Petya is older, he wants to take the chores with complexity larger than some value $x$ ( $h_{i}>x$ ) to leave to Vasya the chores with complexity less than or equal to $x$ ( $h_{i}<=x$ ). The brothers have already decided that Petya will do exactly $a$ chores and Vasya will do exactly $b$ chores ( $a+b=n$ ).
In how many ways can they choose an integer $x$ so that Petya got exactly $a$ chores and Vasya got exactly $b$ chores?
输入格式
The first input line contains three integers $n,a$ and $b$ ( $2<=n<=2000$ ; $a,b>=1$ ; $a+b=n$ ) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers $h_{1},h_{2},...,h_{n}$ ( $1<=h_{i}<=10^{9}$ ), $h_{i}$ is the complexity of the $i$ -th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
The next line contains a sequence of integers $h_{1},h_{2},...,h_{n}$ ( $1<=h_{i}<=10^{9}$ ), $h_{i}$ is the complexity of the $i$ -th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
输出格式
Print the required number of ways to choose an integer value of $x$ . If there are no such ways, print 0.
输入输出样例
输入 #1
5 2 3 6 2 3 100 1
输出 #1
3
输入 #2
7 3 4 1 1 9 1 1 1 1
输出 #2
0
In the first sample the possible values of $x$ are 3, 4 or 5.
In the second sample it is impossible to find such $x$ , that Petya got 3 chores and Vasya got 4.
In the second sample it is impossible to find such $x$ , that Petya got 3 chores and Vasya got 4.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted