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,且相邻数字绝对值之差不 ...
随机推荐
- 运算符、流程控制、while循环
运算符: 1. 算术运算符: “ + ”.“ - ” .“ * ” .“ / ” 分别为加.减.乘.除. # % 是“取模运算符”,就是返回除法的余数.eg. a = 3, b=5, b % a 就是 ...
- 跨域请求Ajax(POST)处理方法
getXSSAjax(function() { //跨域请求 that.ajaxDara(self);}, (bs_tita.webapi || "http://webapi ...
- [K/3Cloud] 在设计时复制已有表单菜单或菜单项快速建立菜单
1.打开已有表单XML,找到FormAppearance的Menu节点,按Ctrl+C复制 <Appearances> <FormAppearance ElementType=&qu ...
- 用jquery校验radio单选按钮(原创)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- [运维]ELK实现日志监控告警
https://blog.csdn.net/yeweiouyang/article/details/54948846
- hdu - 1704 Rank(简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1704 遇到标记过的就dfs,把隐含的标记,最后计数需要注意. #include <cstdio> # ...
- 逆袭指数-——杭电校赛(dfs)
逆袭指数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Memcached与Spring集成的方式(待实践)
主要是基于这几种方式http://www.cnblogs.com/EasonJim/p/7624822.html去实现与Spring集成,而个人建议使用Xmemcached去集成好一些,因为现在官方还 ...
- hbase definitive guide 笔记
ext3 file system 优化 ext3 在用在hbase上可以做如下优化: 1. mount的时候加上noatime选项.这可以减少管理开销 2. 用命令tune2fs -m 0 /dev/ ...
- python实现同服站点地址获取
说明:程序使用http://s.tool.chinaz.com/same此站点查询的结果.使用python简单的实现抓取结果 先随便查询一个结果,抓包分析,如图: 使用python模仿post表单,使 ...