A7959 | Reconnaissance
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most $d$ centimeters. Captain Bob has $n$ soldiers in his detachment. Their heights are $a_{1},a_{2},...,a_{n}$ centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways $(1,2)$ and $(2,1)$ should be regarded as different.
Ways $(1,2)$ and $(2,1)$ should be regarded as different.
输入格式
The first line contains two integers $n$ and $d$ ( $1<=n<=1000,1<=d<=10^{9}$ ) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains $n$ space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed $10^{9}$ .
输出格式
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed $d$ .
输入输出样例
输入 #1
5 10 10 20 50 60 65
输出 #1
6
输入 #2
5 1 55 30 29 31 55
输出 #2
6
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted