The beginning is always wrong, do not know how, and later found that the first sum on the assignment to zero, and then minus is definitely negative, a start sum did not addend, want to leak, suddenly no words, wrote dozens of days, today just solve, hey ~ ~ Note the output may be more than the integer type
http://blog.csdn.net/u014004096/article/details/36876287
Protecting the Flowers
| Time Limit: 2000MS |
|
Memory Limit: 65536K |
| Total Submissions: 4604 |
|
Accepted: 1838 |
Description
Farmer John went to cut some wood and left N (2≤ n ≤100,000) cows eating the grass, as usual. When he returned, he found-to-his horror, the cluster of cows is in his garden eating his beautiful flowers. Wanting to minimize the subsequent damage, FJ decided to take immediate action and transport each cow back to its own barn .
Each cow I was at a location, that's ti minutes (1≤ ti ≤2,000,000) away from its own barn. Furthermore, while waiting for transport, she destroys di (1≤ di ≤100) flowers per minute. No matter how hard he tries, FJ can only transport one cow at a time back to her barn. Moving Cow i to their barn requires 2x ti minutes (ti to get there and ti to return). FJ starts at the flower patch, transports the cow to it barn, and then walks back to the flowers, taking no extra time to Get to the next cow that needs transport.
Write a program to determine the order in which FJ should pick up the cows so and the total number of flowers destroyed I s minimized.
Input
Line 1: A single integer
N
Lines 2..
N+1:each line contains, space-separated integers,
Tiand
Di, that's describe a single cow ' s characteristics
Output
Line 1: A single integer So is the minimum number of destroyed flowers
Sample Input
63 12 52 33 24 11 6
Sample Output
86
Hint
FJ returns the cows in the following order:6, 2, 3, 4, 1, 5. While he's transporting cow 6 to the barn, the others destr Oy flowers; Next he'll take Cow 2, losing to more about his beautiful flora. For the cows 3, 4, 1 he loses, and 6 flowers respectively. When he picks Cow 5 there was no more cows damaging the flowers, so the loss for that Cow is zero. The total flowers lost this to is 24 + 28 + 16 + 12 + 6 = 86.
Source
Usaco January Silver
POJ 3262 protecting the Flowers "greed"