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

Ended

Participants:125

Verdict:Accepted
Score:100 / 100
Submitted:2017-12-31 14:25:11

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
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    vector<int> num;
    for (int i = 0; i < N; ++i) {
        int tmp;
        cin >> tmp;
        num.push_back(tmp);
    }
    sort(num.begin(), num.end());
    int cnt = 0;
    for (int i = 0; i <= N - 3;) {
        if (num[i + 2] - num[i] <= K) {
            ++cnt;
            i = i + 3;
        }       
        else {
            ++i;
        }
    }
    cout << cnt << endl;
    system("pause");
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX