codechef TACHSTCK - "chopsticks" editorial : http://discuss.codechef.com/questions/18267/tachstck-editorial
codechef TACHSTCK - "chopsticks" solution : http://ideone.com/6RPG0U
#include <iostream>#include <cstdio>
#include <cstdlib>
#include <climits>
using namespace std;
int cmp(const void *a, const void *b) {
return (*(int*)a - *(int*)b);}
int main() {
int n, d, l[100005], cnt;
scanf("%d%d", &n, &d);
cnt=0;
l[n]=INT_MAX;
for(int i=0; i<n; i++) scanf("%d", &l[i]);
qsort(l, n, sizeof(int), cmp);
for(int i=0; i<n-1;) {
if(l[i+1]-l[i]<=d) cnt++, i+=2;
else i++;
}
printf("%d\n", cnt);
return 0;
}
No comments:
Post a Comment