Add MUTC 2017 Team 5

This commit is contained in:
Kirigaya Kazuto 2017-08-19 17:28:26 +08:00
parent e3c66c7238
commit a197ab75bd
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,38 @@
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
int testcases;
cin >> testcases;
while (testcases--) {
long long n, m;
long long ex = 0;
cin >> n >> m;
if (m < n - 1) {
ex = n - m - 1;
n = n - ex;
}
long long emax = n*(n - 1) / 2;
long long dec = emax - m;
if (dec < 0)
dec = 0;
long long ans;
//cout << "emax=" << emax << endl;
//cout << "dec =" << dec << endl;
//cout << "ex =" << ex << endl;
if (ex > 0)
ans = 2 * dec + n*(n - 1) + n*ex*(ex+n)+ex*(ex+n-1)*(ex+n);
else
ans = 2 * dec + n*(n - 1);
cout << ans << endl;
}
}

View File

@ -0,0 +1,33 @@
#include <vector>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d %d",&n,&k);
vector<int> vec;
int temp;
for(int i=0;i<n;i++)
{
scanf("%d",&temp);
vec.push_back(temp);
}
sort(vec.begin(),vec.end(),greater<int>());
int cnt=1;
for(int i=0;i<n-1;i++)
{
if(vec[i]-vec[i+1]<=k) ++cnt;
else break;
}
printf("%d\n",cnt);
}
return 0;
}