2744 fish Feed sister paper
time limit: 1 sspace limit: 64000 KBtitle level: Diamonds DiamondTitle Description
Description
In an island nation, most residents are fishermen, and all the towns of the country are scattered in a straight line along the sea. Fishermen catch a lot of fish, but like most fishermen in the world, they do not like to eat, so they decided to adopt some poor family girl paper from China, let them help to eat fish, by the Way (harmony), the State stipulates that the number of poor girls adopted in each town must be equal, so as to build a harmonious society.
A long, straight road runs through the coast to connect all the towns, so each town (except the first and last) is connected directly to the neighboring two towns. A sister of paper to eat a ton of fish a year (but still can keep Slim), each town can be eaten in the local food can also be transported to other cities to eat, in the transport process, a ton of fish per kilometer tribute as tolls.
Each town is known for one year of fishing production, and it is assumed that the transport plan is the best, calculating the maximum number of and that can be collected.
Enter a description
Input Description
The first line of the input file contains an integer N, where 1≤n≤100,000, which represents the total number of towns.
The next n rows each row contains two integers a and B, where 1≤a≤1,000,000,000,0≤b≤1,000,000,000, which represents the location (coordinates) of the town and the fishing output of the town, all towns are given by their location from small to large, and note that there must be positive integer solutions to the problem.
Output description
Output Description
The output file contains only one line with an integer representing the maximum number of sister papers that can be adopted in each town.
Sample input
Sample Input
4
20 300
40 400
340 700
360 600
Sample output
Sample Output
415
Data range and Tips
Data Size & Hint
1≤a≤1,000,000,000,0≤b≤1,000,000,000,1≤n≤100,000
1#include <cstdio>2#include <iostream>3 using namespacestd;4 #defineN 1000015 Long LongA[n],b[n],maxx;6 intN;7 BOOLCheckLong Longx)8 {9 Long Longcarry=0;//a little greedy algorithmTen for(intj=1; j<n; J + +) One { ACarry+=b[j]-x;//number of locations shipped to J - if(carry<0)//if carry is a negative value -carry-=a[j+1]-A[J];//It's a negative value (equivalent to a positive value from the opposite) . the Else//if carry is a positive value - if(carry<a[j+1]-A[J])//if the carry is consumed by the path length, the carry is 0; -carry=0; - Else//otherwise carry-shipping +carry-=a[j+1]-A[j]; - } + returncarry+b[n]>=x;//number of positions transported to n-1 +n the number of positions itself compared to the X position (assuming optimal position) A //If true, the assumption is small, if false, the assumption is too large. at } - intMain () - { -scanf"%d",&n); - for(intI=1; i<=n; i++) - { inCin>>a[i]>>B[i]; -Maxx=max (Maxx,b[i]);//Select the right border to } + Long LongL=1, r=Maxx,mid; - while(l<=R) the { *Mid= (l+r) >>1; $ if(check (mid))Panax NotoginsengL=mid+1; - Else ther=mid-1; + } Acout<<l-1<<Endl; the return 0; +}
Fish Feed sister paper