Equator |
Time Limit: 2000ms, Special Time Limit:5000ms,Memory Limit:65536KB |
Total submit users: 12, Accepted users:8 |
Problem 13248 : No special judgement |
Problem description |
In a galaxy far away, the planet Equator is under attack! The evil gang Galatic Criminal People Cooperation is planning robberies in Equator’s cities. Your help is needed! In order to complete your training for becoming a lord of the dark side you should help them deciding which cities to rob. As the name says, the desert planet Equator only can be inhabited on its equator. So the gang lands there at some point and travels into some direction robbing all cities on their way until leaving the planet again. The cities differ in value: some are richer, some are poorer, some have better safety functions. So the gang assigned expected profits or losses to the cities. Help them deciding where to begin and where to end their robbery to maximize the money in total when robbing every city in between.
|
Input |
|
Output |
For each test case print one integer describing the maximum money they can make in total. |
Sample Input |
3 3 1 2 3 8 4 5 -1 -1 1 -1 -1 5 2 -1 -1 |
Sample Output |
6 14 0 |
在这里继续介绍一种新的方法,这个原理就是把数组的大小开成两倍,建一个队列,保证队列单增,队列里的值是数组前n项和,那么子段的最大和就是队尾减队首。 代码如下:
|
循环数组求最大子段和系列------方法2
最新推荐文章于 2018-12-18 19:52:00 发布