USACO 2008 Open Silver-Cow Cars

Description

N (1 ≤ N ≤ 50,000) cows conveniently numbered 1..N are driving in separate cars along a highway in Cowtopia. Cow ican drive in any of M different high lanes (1 ≤ M ≤ N) and can travel at a maximum speed of Si (1 ≤ Si ≤ 1,000,000) km/hour.

After their other bad driving experience, the cows hate collisions and take extraordinary measures to avoid them. On this highway, cow i reduces its speed by D (0 ≤ D ≤ 5,000) km/hour for each cow in front of it on the highway (though never below 0 km/hour). Thus, if there are K cows in front of cow i, the cow will travel at a speed of max[Si - D × K, 0]. While a cow might actually travel faster than a cow directly in front of it, the cows are spaced far enough apart so crashes will not occur once cows slow down as described,

Cowtopia has a minimum speed law which requires everyone on the highway to travel at a a minimum speed of L (1 ≤L ≤ 1,000,000) km/hour so sometimes some of the cows will be unable to take the highway if they follow the rules above. Write a program that will find the maximum number of cows that can drive on the highway while obeying the minimum speed limit law.

Input

* Line 1: Four space-separated integers: NMD, and L

* Lines 2..N+1: Line i+1 describes cow i's initial speed with a single integer: Si

Output

* Line 1: A single integer representing the maximum number of cows that can use the highway

Sample Input

3 1 1 5
5
7
5

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

Sample Output

2

Hint

SAMPLE 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 DETAILS:

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


先将牛按速度升序排列,枚举每一头牛,每次将牛放入车辆最少的那条车道,可说明这样做是最优的。

#include <iostream>
#include <algorithm>
#define maxn 50006
int n,m,d,l,tnt,k;
int v[maxn],a[maxn];
using namespace std;
int main()
{
  while(cin>>n>>m>>d>>l)
  {
  int i;
    for(i=0;i<n;i++)
     cin>>v[i];
     sort(v,v+n);
     k=1;
     for(i=0;i<n;i++)
     {
         if(v[i]-a[k]*d>=l)
         {
             tnt++;
             a[k]++;
             k++;
             if(k>m) k=1;
         }
     }
     cout<<tnt<<endl;
}
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值