当前位置:网站首页>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;
}
边栏推荐
- [leetcode] integer inversion [7]
- Do a small pressure test with JMeter tool
- 嵌入式数据库开发编程(六)——C API
- 质量体系建设之路的分分合合
- To be continued] [UE4 notes] L4 object editing
- Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
- 2022/7/2 question summary
- [paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
- Basic knowledge points
- Unity shot tracking object
猜你喜欢
随机推荐
[转]MySQL操作实战(一):关键字 & 函数
Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
2022/7/1 learning summary
Stm32cubemx (8): RTC and RTC wake-up interrupt
Basic knowledge points of dictionary
Es module and commonjs learning notes
Pointnet++的改进
一个新的微型ORM开源框架
Redis has four methods for checking big keys, which are necessary for optimization
Cocos2dx screen adaptation
2022/7/1學習總結
C language Essay 1
LeetCode之單詞搜索(回溯法求解)
[转]:Apache Felix Framework配置属性
PMP考试敏捷占比有多少?解疑
[turn]: OSGi specification in simple terms
Learning notes of "hands on learning in depth"
小程序直播+电商,想做新零售电商就用它吧!
Do a small pressure test with JMeter tool
Lua GBK and UTF8 turn to each other