-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcch2.cpp
More file actions
43 lines (37 loc) · 849 Bytes
/
Copy pathcch2.cpp
File metadata and controls
43 lines (37 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
int t,n,d,a[100005],i,j,current,county,flag;
long long int sum;
scanf("%d",&t);
while(t--)
{
sum =0;
scanf("%d%d",&n,&d);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
for(i=n-1;i>=0;i--)
{
//cout<<i<<"**"<<a[i]<<endl;
current = a[i];
i--;
if(i<0)
break;
//cout<<i<<" ** "<<a[i]<<endl;
if(current - a[i] < d)
{
//cout<<current<<" "<<a[i]<<endl;
sum+=current+a[i];
}
else
i++;
}
printf("%lld\n",sum);
}
return 0;
}