State planning P4270 little odd mining 2

Problem Description

[Title] background

Little bit strange spacecraft opens up unlimited endurance + precise acquisition mode! To this it shipped ore to ore market sources floodlight, the upgrade to unlimited non-probabilistic spacecraft engines.

 

【Problem Description】

There are m + 1 planet, from left to right numbered 0 to m, the first planet small odd number 0.

N has the ore, ore body at the i-th unit ore ai, bi on the first planet.

As the spacecraft using an older engine jump every time it can only move from planet to No. x + x 4 stars or No. 7 x + planet. Every planet a little odd will go all the ore mining on the planet, seeking the maximum number of ore can be taken to the odd small.

Note that small odd number m does not have to reach the final planet.

Input Format

The first line of two integers n, m.

Next n lines of two integers ai, bi.

Output Format

Output line an integer representing the required results.

Sample input

3 13
100 4
10 7
1 11

Sample Output

101

prompt

Sample explain]

First from 0 to 4, from 4 to 11 times a second, to a total of 101 units ore mining.

 

【data range】

20% of the data for n = 1, m <= 10 ^ 5

40% of the data for n <= 15, m <= 10 ^ 5

For 60% of the data m <= 10 ^ 5

To 100% of the data n <= 10 ^ 5, m <= 10 ^ 9,1 <= ai <= 10 ^ 4,1 <= bi <= m

 
analysis
Stage: by number of small to large discussion
Status: f [i]; i before the maximum benefit can be obtained in the planet
Decision: The first four or before 7
方程:f[i]=max{f[i-4],f[i-7]}+a[i]
Time complexity o (m) 
Obviously I could not pass
optimization:
Obviously the distance between the two planets to be able to be expressed as 4a + 7b
After playing seen from Table 18 after reachable, so the distance is larger than 18, the entire 18 to change. (Discrete)
At this time complexity o (18n)
Be over
 

Guess you like

Origin www.cnblogs.com/CXYscxy/p/11028136.html