N (1 <= N <= 50,000) cows conveniently numbered 1..N are driving in separate cars along a highway in Cowtopia. Cow i can drive in any of M different high lanes (1 <= M <= N) and can travel at a maximum speed of S_i (1 <= S_i <= 1,000,000) km/hour.ui
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[S_i - 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 asthis
described,spa
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.code
編號爲1到N的N只奶牛正各自駕着車打算在牛德比亞的高速公路上飛馳.高速公路有M(1≤M≤N)條車道.奶牛i有一個本身的車速上限Si(l≤Si≤1,000,000).blog
在經歷過糟糕的駕駛事故以後,奶牛們變得十分當心,避免碰撞的發生.每條車道上,若是某一隻奶牛i的前面有南只奶牛駕車行駛,那奶牛i的速度上限就會降低kD個單位,也就是說,她的速度不會超過Si – kD(O≤D≤5000),固然若是這個數是負的,那她的速度將是0.牛德比亞的高速會路法規定,在高速公路上行駛的車輛時速不得低於/(1≤L≤1,000,000).那麼,請你計算有多少奶牛能夠在高速公路上行駛呢?排序
Line 1: Four space-separated integers: N, M, D, and Lthree
There are three cows with one lane to drive on, a speed decrease of 1, and a minimum speed limit of 5.it
Two cows are possible, by putting either cow with speed 5 first and the cow with speed 7 second.io
從小到大排序,而後貪心選擇車道;ast
1 #include<cstdio> 2 #include<algorithm> 3 #define LL long long 4 const int maxn=1e5+10; 5 LL n,m,ans; 6 struct nate{LL t,d;}s[maxn]; 7 bool comp(nate x,nate y){return x.t*y.d<x.d*y.t;} 8 int main(){ 9 scanf("%lld",&n); 10 for(int i=1;i<=n;i++){ 11 scanf("%lld%lld",&s[i].t,&s[i].d); 12 s[i].t*=2,m+=s[i].d; 13 } 14 std::sort(s+1,s+n+1,comp); 15 for(int i=1;i<=n;i++){ 16 m-=s[i].d; 17 ans+=s[i].t*m; 18 } 19 printf("%lld\n",ans); 20 return 0; 21 }