Greedy parts processing solution to a problem

 

 

 

1019: B06- greedy - machining parts [improved group]

Time limit: 1 Sec Memory Limit: 128 MB
submit: 24 Solution: 7
[ submit ] [ state ] [ Discussion Board ] [proposition man: External Import]

Title Description

      A recent small artisans K n of parts to be machined. Each part needs ti days to complete, each part of each day of delay processing have to pay a certain fine si. The number of days of delay counting from the day to day work began, the first part is not working fine. Now small K want to know how to arrange the order processing can make him pay fines to a minimum, the minimum is.
      This number may be very large, output a result of the number of modulo m.

 

Entry

Enter the file name process.in.
A first line input integer n, the total number of parts to be machined.
Conduct a second integer m, m represents modulo To answer.
Of ~ 3 n + 2 rows, each row two integers ti and si.

 

Export

Output file name process.out.
Only one line output, an integer, K represents the results of a small penalty to pay for a minimum modulo m.

 

Sample input

2
100 
2 33 
33 2

 

Sample Output

4

 

prompt

[1] Input Output Sample explained

 

A first processing section, takes two days, a second reprocessing. Required to pay a fine of 2 × 2 = 4.

 

Sample 2 [O] process.in                      

4

100

3 3

6 4

2 2

8 5                                

 

process.out

81

 

[O 2] Sample Dictionary

If the processing order of 1 → 2 → 3 → 4, it is necessary to pay a fine of 0 × 3 + 3 × 4 + (3 + 6) × 2 +

(3+6+2)×5=85;

Best solution is 3 → 1 → 2 → 4, this time is required to pay a fine 0 × 2 + 2 × 3 + (2 + 3) × 4 + (2 + 3 + 6) × 5 = 81.

【data range】

For 40% of the data, 0 < n- ≤10,000,0 < T I , S I ≤ 10,000;

For 80% of the data, 0 < n- ≤100,000,0 < T I , S I ≤2 × 10 . 9 , 0 < m ≦ 10 . 8 ;
100% of the data, 0 < n- ≤100,000,0 < Ti , Si ≤ × 10 2 . 9 , 0 < m ≦ 10 18 is .

Source / classification

The questions seem so hard like ducks Come

 

 The above is issued for a teacher to explain () ( "if", "thoughts")

Well, since the positive solutions are out card a card to try it

 

Guess you like

Origin www.cnblogs.com/Tidoblogs/p/11260264.html