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,且相邻数字绝对值之差不 ...
随机推荐
- Xterm256终端颜色的名称
hi x016_Grey0 ctermfg=16 guifg=#000000 "rgb=0,0,0 hi x017_NavyBlue ctermfg=17 guifg=#00005f &qu ...
- [bzoj1059][ZJOI2007]矩阵游戏_二分图最大匹配
矩阵游戏 bzoj-1059 ZJOI-2007 题目大意:给定一个n*n的棋盘,上面有一些格子被染黑,剩下都是白色.你每次可以交换两列或者两行,问你能否通过一系列操作使得棋盘的主对角线上的格子全是黑 ...
- 绿盟NF防火墙系统
http://www.nsfocus.com.cn/ http://www.nsfocus.com.cn/products/details_22_5.html
- 几点平时不太注意的CSS知识
1:文本显示的时候,我们发现左右参差不齐,text-align:justify 就能让文本左右都齐刷刷的啦: 2:input标签的内容,处于安全考虑,有时候我们并不希望别人黏贴复制,这时候这样干:& ...
- 自己构建的Lumbda表达式
自己构建的Lumbda表达式 定义接口: package com.stono.lambda; public interface Add { public void add(int x, int y); ...
- day1--大数据概念,hadoop介绍,hdfs整体运行机制
1.什么是大数据 基本概念 在互联网技术发展到现今阶段,大量日常.工作等事务产生的数据都已经信息化,人类产生的数据量相比以前有了爆炸式的增长,以前的传统的数据处理技术已经无法胜任,需求催生技术,一套用 ...
- 菜鸟学python-基础(2)
变量命名: 1)必须以字符或下划线开头 2)以单下划线开头(_fo)表示不能直接訪问的类属性,须要类提供的接口进行訪问 3)以双下划线开头(__foo)的代表类的私有成员 4)以双下划线开头(__fo ...
- SDUTOJ 2476Period
#include<iostream> #include<string.h> #include<stdio.h> #define N 1000010 using na ...
- 水晶报表 Crystal Report 调用存储过程时出错 找不到表 ,解决方法。
用 CrystalReportViewer1 控件在asp.net的网页上显示报表,假设做报表时调用数据表数据的方式调用是能够成功的.但报表是用存储过程获取数据方式会出现下面错误: 找不到表'RptO ...
- STM32学习之路-感觉自己走到了一个天大的坑里了!
先前兴致勃勃的来弄16位并口驱动LCD.本以为就须要改下LCD IC的初始化即可了,没想到弄了这么多天最终发现自己走进了一个深坑了 T T 原因是我的开发板是奋斗V5的, 它确实有MCU外扩IO口, ...