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

Ended

Participants:125

Verdict:Accepted
Score:100 / 100
Submitted:2017-12-31 13:18:50

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
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
#define iof freopen("in.txt", "r", stdin)
#define loop(i, a, b) for (int i = a; i <= b; i++)
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define min(a, b) (((a) < (b)) ? (a) : (b))
int main()
{
    //iof;
    vi a;
    int n, k;
    cin >> n >> k;
    a.resize(n + 1);
    loop(i, 1, n) cin >> a[i];
    sort(a.begin()+1, a.end());
    int ans=0, tot=n, head=1;
    while (tot>=3){
        if (a[head+2]-a[head]<=k) {
            ans++;
            head+=3;
            tot-=3;
        }else{
            head+=1;
            tot-=1;
        }
    }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX