[Offer收割]编程练习赛42 register

Ended

Participants:125

Verdict:Accepted
Score:100 / 100
Submitted:2017-12-31 12:42:12

Lang:G++

Edit
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
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    //freopen("E:\\input.txt", "r", stdin);
    int N, K;
    scanf("%d %d", &N, &K);
    int a[100100];
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &a[i]);
    }
    sort(a, a + N);
    int res = 0;
    for (int i = 0; i < N-2;i++)
    {
        if (a[i] + K >= a[i + 2]) {
            res++;
            i = i + 2;
        }           
    }
    cout << res;
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX