当前位置:网站首页>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;
}
边栏推荐
- Do a small pressure test with JMeter tool
- C iterator
- [转]MySQL操作实战(一):关键字 & 函数
- Reverse one-way linked list of interview questions
- C # perspective following
- Listview pull-down loading function
- [转]:Apache Felix Framework配置属性
- Embedded database development programming (V) -- DQL
- Use of snippets in vscode (code template)
- 使用Room数据库报警告: Schema export directory is not provided to the annotation processor so we cannot expor
猜你喜欢

Double pointer Foundation

Ue4/ue5 illusory engine, material part (III), material optimization at different distances

Shell Sort

Count sort

Download and use of font icons

Unity find the coordinates of a point on the circle

Learning notes of "hands on learning in depth"

Panel panel of UI

一个新的微型ORM开源框架

django连接数据库报错,这是什么原因
随机推荐
Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
C iterator
Vs2015 secret key
C语言杂谈1
Quick sort summary
Es module and commonjs learning notes
Do a small pressure test with JMeter tool
Lua GBK and UTF8 turn to each other
Embedded database development programming (zero)
Magnifying glass effect
Data is stored in the form of table
嵌入式数据库开发编程(五)——DQL
64 horses, 8 tracks, how many times does it take to find the fastest 4 horses at least
被舆论盯上的蔚来,何时再次“起高楼”?
Animation
Simple modal box
The difference between heap and stack
Cocos create Jiugongge pictures
Lua wechat avatar URL
[转]MySQL操作实战(三):表联结