hiho week 72 register

Ended

Participants:370

Verdict:Accepted
Score:100 / 100
Submitted:2015-11-20 20:57:02

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 <cstdio>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i < b; i++)
int a[100000];
int main() {
    int n,m,h,r;
    scanf("%d %d %d %d",&n,&m,&h,&r);
    rep(i,0,n) scanf("%d",&a[i]);
    std::sort(a,a+n);
    int res = 0,ans = 0;
    if(a[0]<=r) {
        ans = 1;
        rep(i,1,n) {
            if(a[i]>r+ans) break;
            if(a[i]-a[i-1]>m) {
                res += ans;
                ans = 0;
                if(a[i]>r) break;
            }
            ans ++;
        }
    }
    res += ans;
    if(res>h) res = h;
    printf("%d\n",res);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX