当前位置:网站首页>Haut OJ 1218: maximum continuous sub segment sum
Haut OJ 1218: maximum continuous sub segment sum
2022-07-05 05:17:00 【hunziHang】
Problem description :
give n Number , Find out n The sum of the largest continuous sub segments in the number .
Input :
The input is divided into two lines , The first line is a positive integer n, Second line input n It's an integer xi,
If the sum of the largest subsegments is negative , Output 0.
2<=n<=100000,-1000<=x<=1000.
Output :
Output the maximum continuous sub segment and .
The sample input :
5 1 2 -4 2 3
Sample output :
5
Cause analysis :
utilize sum And 0 The relationship between , To determine whether the previous data is valuable to the results , If the previous value is negative , The fu 0, It is equivalent to rewriting the starting sub column , If it is greater than 0 It means it is valuable , Can continue
Solution :
#include<stdio.h>
int main()
{
int n, i, j, k, x, ans, sum;
scanf("%d", &n);
ans = 0;sum = 0;
for (i = 1;i <= n;i++)
{
scanf("%d", &x);
sum += x;
if (sum > ans)
ans = sum;
if (sum < 0)
sum = 0;
}
printf("%d\n", ans);
return 0;
}
边栏推荐
- Quick sort summary
- Personal required code
- [leetcode] integer inversion [7]
- Embedded database development programming (zero)
- Bubble sort summary
- Reverse one-way linked list of interview questions
- To the distance we have been looking for -- film review of "flying house journey"
- [to be continued] [UE4 notes] L1 create and configure items
- Es module and commonjs learning notes
- 小程序直播+电商,想做新零售电商就用它吧!
猜你喜欢
远程升级怕截胡?详解FOTA安全升级
[to be continued] [UE4 notes] L1 create and configure items
用 Jmeter 工具做个小型压力测试
JVM call not used once in ten years
Grail layout and double wing layout
[turn to] MySQL operation practice (III): table connection
stm32Cubemx(8):RTC和RTC唤醒中断
Unity check whether the two objects have obstacles by ray
Collapse of adjacent vertical outer margins
Download and use of font icons
随机推荐
Stm32cubemx (8): RTC and RTC wake-up interrupt
PMP candidates, please check the precautions for PMP examination in July
A complete attack chain
Personal required code
UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
Under the national teacher qualification certificate in the first half of 2022
Transport connection management of TCP
Download xftp7 and xshell7 (official website)
[LeetCode] 整数反转【7】
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
[trans]: spécification osgi
服务熔断 Hystrix
[turn]: OSGi specification in simple terms
FVP和Juno平台的Memory Layout介绍
JVM call not used once in ten years
A three-dimensional button
[转]MySQL操作实战(一):关键字 & 函数
YOLOv5添加注意力机制
[merge array] 88 merge two ordered arrays