2017杭电多校第五场11Rikka with Competition
Rikka with Competition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 445 Accepted Submission(s): 366
A wrestling match will be held tomorrow. n players
will take part in it. The ith
player’s strength point is ai.
If there is a match between the ith
player plays and the jth
player, the result will be related to |ai−aj|.
If |ai−aj|>K,
the player with the higher strength point will win. Otherwise each player will have a chance to win.
The competition rules is a little strange. Each time, the referee will choose two players from all remaining players randomly and hold a match between them. The loser will be be eliminated. After n−1 matches,
the last player will be the winner.
Now, Yuta shows the numbers n,K and
the array a and
he wants to know how many players have a chance to win the competition.
It is too difficult for Rikka. Can you help her?
the number of the testcases. And there are no more than 2 testcases
with n>1000.
For each testcase, the first line contains two numbers n,K(1≤n≤105,0≤K<109).
The second line contains n numbers ai(1≤ai≤109).
5 3
1 5 9 6 3
5 2
1 5 9 6 3
1
Statistic | Submit | Discuss | Note
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
int t;
scanf("%d",&t);
ll n,m;
while(t--)
{
scanf("%lld%lld",&n,&m);
ll tmp=n*(n-1)/2;
ll result=0;
if(m>=tmp)
{
result=n*(n-1);
}
else if(m>n-1&&m<tmp)
{
result=(n*(n-1))+(tmp-m)*2;
}
else
{
ll p=m+1,q=n-m-1;
result=m*m*2+(n-m-1)*(n-m-2)*n+p*q*2*n;
}
cout<<result<<endl;
}
return 0;
}
2017杭电多校第五场11Rikka with Competition的更多相关文章
- 2017杭电多校第五场Rikka with Subset
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2017杭电多校第六场1008 Kirinriki
传送门 Kirinriki Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2018杭电多校第五场1002(暴力DFS【数位】,剪枝)
//never use translation#include<bits/stdc++.h>using namespace std;int k;char a[20];//储存每个数的数值i ...
- 2017杭电多校第六场1011Classes
传送门 Classes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- 2017杭电多校第六场03Inversion
传送门 Inversion Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2017杭电多校第七场1011Kolakoski
Kolakoski Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Tota ...
- 2017杭电多校第七场1005Euler theorem
Euler theorem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) ...
- hdu6356 Glad You Came 杭电多校第五场 RMQ ST表(模板)
Glad You Came Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- [2019杭电多校第五场][hdu6630]permutation 2
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6630 题意为求出1-n,n个数的全排列中有多少种方案满足第一位为x,第n位为y,且相邻数字绝对值之差不 ...
随机推荐
- Spring实战读书笔记
Spring实战读书笔记 Spring-core Spring之旅 - DI 和 AOP 概念 spring 的Bean容器 spring 的 核心模块 Spring的核心策略 POJO 最小侵入式编 ...
- 洛谷——P1044 栈
P1044 栈——卡特兰数 题目背景 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表. 栈有两种最重要的操作,即pop(从栈顶弹出一个元素)和push(将一个元素进栈) ...
- Java内存分配与参数传递
JAVA中方法的参数传递方式只有一种:值传递. JAVA内存分配: 1.栈:存放 基本类型的数据.对象的引用(类似于C语言中的指针) 2.堆:存放用new产生的数据 3.静态域:存放在对象中用stat ...
- Orcle定时生成表数据作业
--建表 create table table41( id ) not null, --主键 col1 ), col2 ), col3 ), col4 int, col5 timestamp, col ...
- java压缩与解压文件
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import ...
- 第三课 MongoDB 数据更新
1.课程大纲 本课程主要解说 MongoDB 数据更新的相关内容.包含文档插入 insert 函数.文档删除 remove函数以及文档更新update函数的基本使用.除此之外.还会介绍 MongoDB ...
- DataNucleus之JDO操作演示样例
JDO(Java Data Object )是Java对象持久化的新的规范.也是一个用于存取某种数据仓库中的对象的标准化API. 注意JDO是一种规范,而不是一个产品.而DataNucleus正是实现 ...
- JSP页面怎样导入优酷视频
我在做的一个项目里面,应客户要求.要导入视频.然后我再考虑,视频是直接放在本地数据库的话,那么肯定会出现数据视频读取反应慢. 那么,就能够把视频先传到优酷上面,然后再直接应用优酷视频上的html代码, ...
- 在HDInsight中从Hadoop的兼容BLOB存储查询大数据的分析
在HDInsight中从Hadoop的兼容BLOB存储查询大数据的分析 低成本的Blob存储是一个强大的.通用的Hadoop兼容Azure存储解决方式无缝集成HDInsight.通过Hadoop分布式 ...
- io口的作用
I/O接口的作用 主机与外界交换信息称为输入/输出(I/O).主机与外界的信息交换是通过输入/输出设备进行的.一般的输入/输出设备都是机械的或机电相结合的产物,比方常规的外设有键盘.显示器.打 ...