# 贪心-BZOJ-1623-[Usaco2008 Open]Cow Cars 奶牛飞车

Description

Input

N<=50000
Output

Sample Input
3 1 1 5//三头牛开车过一个通道.当一个牛进入通道时，它的速度V会变成V-D*X(X代表在它前面有多少牛),它减速后，速度不能小于L

5

7

5

INPUT DETAILS:

There are three cows with one lane to drive on, a speed decrease

of 1, and a minimum speed limit of 5.

Sample Output
2

OUTPUT DETAILS:

Two cows are possible, by putting either cow with speed 5 first and the cow

with speed 7 second.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long int n,m,s[50005],d,l,num[50005];
typedef struct qnode
{
long long int num;
qnode(long long int _num=0):num(_num){}
bool operator <(const qnode &r)const{return num>r.num;}
}qnode;
int main()
{
long long int out=0;
qnode k;
cin >> n >> m >> d >> l;
for(long long int i=0;i<n;i++)
cin >> s[i];
sort(s+0,s+n);
priority_queue<qnode>q;
for(long long int i=0;i<m;i++)
q.push(qnode(0));
for(int i=0;i<n;i++)
{
k=q.top();
if(s[i]-k.num*d>=l)
{
out++;
q.pop();
k.num++;
q.push(k);
}
}
cout << out << endl;
return 0;
}
03-10 141

04-04 23
04-06 29
09-26 181
05-15 36