当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Fragment addition failed error lookup
![[转]: OSGI规范 深入浅出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[转]: OSGI规范 深入浅出

Romance of programmers on Valentine's Day
![[轉]: OSGI規範 深入淺出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[轉]: OSGI規範 深入淺出

Embedded database development programming (VI) -- C API
![[interval problem] 435 Non overlapping interval](/img/a3/2911ee72635b93b6430c2efd05ec9a.jpg)
[interval problem] 435 Non overlapping interval
![[to be continued] [UE4 notes] L2 interface introduction](/img/0f/268c852b691bd7459785537f201a41.jpg)
[to be continued] [UE4 notes] L2 interface introduction

Research on the value of background repeat of background tiling

Quick sort summary

嵌入式数据库开发编程(零)
随机推荐
win10虚拟机集群优化方案
Solon 框架如何方便获取每个请求的响应时间?
GameObject class and transform class of unity
Leetcode word search (backtracking method)
Cocos2dx screen adaptation
Research on the value of background repeat of background tiling
UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
C language Essay 1
Out and ref functions of unity
Three dimensional dice realize 3D cool rotation effect (with complete source code) (with animation code)
[to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
Dotween usage records ----- appendinterval, appendcallback
Unity get component
BUUCTF MISC
Use of snippets in vscode (code template)
嵌入式数据库开发编程(六)——C API
质量体系建设之路的分分合合
Learning notes of "hands on learning in depth"
[轉]: OSGI規範 深入淺出
C语言杂谈1