第四届吉林省大学生程序设计大赛个人解题报告 Problem J: Buying and Selling

Problem J: Buying and Selling


Mr. Skywind has received a request from his friend Lesley, who is a stock analyst Lesley is focusing on the buying and selling quantity now. She will found a mathematics model on these values. As you know, every day, a lot of people se stocks, and a lot of people buy. The quantities of stocks which are concluded are equal certainly. But the quantity that people want to sell and the value that people want to buy is not same. If buying quantity is more than selling, the difference indicated by a positive number is call net buying. Opposite, if the buying is small, the number is expressed using a negative number. So it can be called net-buying-selling value.
Although the difference is recoded every day, what Lesley focus is not only the daily value but also the sum of continuous days. When a series of history stock data is given, Lesley wants to know that in which days the sum of net-buying-selling is maximum and positive or the sum is minimal and negative. Although Lesley can do some easy programming, it is hard to find an effective algorithm for a lot of data. Now it is the time that you write this program to help her.

Input
There are several test cases in input file. The first line of each case is an integer n(2<=n<=100,000) followed by n numbers which are less than 10,000. The end of input is indicated by a zero.


Output
For each case, two numbers are needed. The first is the maximum and positive sum of net-buying-selling in some continuous days; the second is the minimal and negative. You can assure there is one positive and one negative value at least.


Sample Input
6
1 2 3 -3 -2 -5
0


Sample Output
6 -10

 

这道题是一道简单求最大子段和,最小子段和的题目,这是DP的典型题,就不做过多说明了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值