SDOI2013 Protection of the author

Source: Internet
Author: User

Description, the person Ming Ming think to SDOI2012 the topic is too terrible, because always to be scolded, so he gave SDOI2013 a question.

The children who participated in the SDOI2012 released a large number of zombies in an attempt to attack Ming Ming's home. And you as a SDOI2013 contestant, you need to protect the topic of the person Ming Ming.

Zombies are approaching from the only straight road, and you need to place plants in front of Ming's door to attack zombies and prevent zombies from hitting the house. First off, a blood-A1-point zombie from the house x1 meters at a constant pace, you placed the damage to the Y1 point/second plant for defense; the second, on the basis of the previous level, the zombie queue to increase the number of a A2 point of the Zombie, and the latter a zombie distance d m, from the house x2 meters at a constant pace, You re-place the damage to Y2 points/second plants; n n off, zombie queue has a total number of zombies, two adjacent zombies distance d m, Pai Tau

Zombie blood volume is an dot, the second zombie blood volume a_n−1, and so on, and so on, the queue of zombies from the house xn meters at a constant pace, the rest of the zombies follow the queue at the same time, you re-place the damage to yn points/second plant.

Each zombie moves in a straight line at 1 m/s, and as the plant shoots faster than the zombie movement, it can ignore the time of the plant bullets in the air. All zombies are present and close together, so when a zombie dies, the next zombie immediately begins to be harmed by a plant bullet.

The game score depends on the total amount of plant damage you place Σyi (1<=i<=n), and the smaller the higher the score, in order to pursue the upper bound of the score, you have to place every level of damage as small as possible plants.

As a SDOI2013 contestant, can you protect the people who have the quiz? input first line two spaces separated by positive integers n and D, respectively, indicating the distance between the closing number and the adjacent zombies.

The next n rows are two spaces separated by a positive integer, and the i + 1 acts AI and XI, respectively, representing the

In the zombie queue to increase the amount of blood for the AI point of the zombie, the first spawn zombie from the House XI meters began to approach. output a number, n off the minimum sum of plant attack damage, reserved to an integer. Sample Input
5 2

3 3

1 1

10 8

4 8

2 3
Sample Output
7
data constraint for 30%, n≤10^3;

For 50% of data, n≤10^4;

For 70% of data, 1≤n≤10^5,1≤d≤10^6, 1≤x≤10^6, 1≤a≤10^6;

For 100% of data, 1≤n≤10^5,1≤d≤10^12, 1≤x≤10^12, 1≤a≤10^12; Hint Sample description:

First off: 3 meters away from the house has a blood volume of 3 points of the zombie, plant minimum attack power of 1.00000;

The second off: 1 meters away from the house has a blood volume of 1 Points of zombies, 3 meters of blood 3 points of the zombie, plant the minimum damage to 1.33333;

Third off: 8 meters away from the house has a blood volume of 10 points of zombies, 10 meters of blood 1 points of the zombie, 12 meters of blood 3 points of the zombie, plant the minimum damage to 1.25000;

Four off: 8 meters away from the house has a blood volume of 4 points of the zombie, 10 meters of blood 10 points of the zombie, 12 meters of blood 1 points of the zombie, 14 meters of blood 3 points of the zombie, plant the minimum damage is 1.40000;

The last: 3 meters away from the house has a blood volume of 2 zombies, 5 meters of blood 4 points of the zombie, 7 meters of blood 10 points of the zombie, 9 meters of blood 1 points of the zombie, 11 meters in the blood 3 points of the zombie, plant the minimum damage is 2.28571.

The minimum sum of plant attack damage is 7.26905.

We set F[i]=sigma (A[j]) (1<=j<=i)

So for each level, the answer is the maximum value of the slope of the preceding point (Sigma (A[j-1]), j*d) and (Sigma (A[i)), x[i]+i*d)

After observation we find that the optimal solution must be on the lower convex hull, and the slope on the convex hull is a single-peak function, because we can maintain (sigma[i-1],i*d) the bottom convex hull, each time the three-point solution on the convex hull

Oh. The last one reserved to the whole number is rounded ha.

#include <cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<cstring>using namespacestd;structpoint{Doublex, y; Point (Double_x=0,Double_y=0) {x=_x;y=_y; }};p ointoperator+ (point A,point b) {returnPoint (a.x+b.x,a.y+b.y);} Pointoperator-(point A,point b) {returnPoint (a.x-b.x,a.y-b.y);}Double operator^ (Point A,point B) {returna.x*b.y-a.y*b.x;}DoubleXL (Point A,point b) {return(B.Y-A.Y)/(b.x-a.x);} Point tu[100011],ne;Doubletmp,a[100011],x[100011],pre[100011],d;Doubleans;inti,n,t;Doublefind (point x) {intFn,i,l,r,mid1,mid2; DoubleAns1,ans2,ret; L=1; R=T;  while(L +2<R) {fn= (r-l)/3; Mid1=l+fn;mid2=mid1+fn; Ans1=XL (tu[mid1],x); ans2=XL (TU[MID2],X); if(ANS1&LT;ANS2) l=mid1+1; Elser=mid2-1; } ret=0;  for(i=l;i<=r;i++) ret=Max (RET,XL (tu[i],x)); returnret;}intMain () {scanf ("%D%LF",&n,&d);  for(i=1; i<=n;i++) {scanf ("%LF%LF",&a[i],&X[i]); Pre[i]=pre[i-1]+A[i]; }     for(i=1; i<=n;i++) {NE=point (i*d,pre[i-1]);  while(t>1&& (tu[t]-tu[t-1]) ^ (ne-tu[t-1])) <0) t--; tu[++t]=NE; NE=point (x[i]+i*D,pre[i]); Ans+=find (NE); } printf ("%.0lf\n", ans);}

SDOI2013 Protection of the author

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.