当前位置:网站首页>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;
}
边栏推荐
- Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
- Data is stored in the form of table
- Kali 2018 full image download
- Stm32cubemx (8): RTC and RTC wake-up interrupt
- To the distance we have been looking for -- film review of "flying house journey"
- Unity ugui source code graphic
- Common database statements in unity
- Merge sort
- [LeetCode] 整数反转【7】
- [trans]: spécification osgi
猜你喜欢

Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory

2022/7/2 question summary

Unity get component

Applet live + e-commerce, if you want to be a new retail e-commerce, use it!

Binary search basis

National teacher qualification examination in the first half of 2022
![[转]: OSGI规范 深入浅出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[转]: OSGI规范 深入浅出

Django reports an error when connecting to the database. What is the reason

Learning notes of "hands on learning in depth"
![[trans]: spécification osgi](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[trans]: spécification osgi
随机推荐
Pause and resume of cocos2dx Lua scenario
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
Unity check whether the two objects have obstacles by ray
小程序直播+电商,想做新零售电商就用它吧!
[trans]: spécification osgi
Three dimensional dice realize 3D cool rotation effect (with complete source code) (with animation code)
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
National teacher qualification examination in the first half of 2022
Unity and database
[turn to] MySQL operation practice (I): Keywords & functions
[merge array] 88 merge two ordered arrays
[转]MySQL操作实战(三):表联结
Chinese notes of unit particle system particle effect
[interval problem] 435 Non overlapping interval
Unity get component
[to be continued] [UE4 notes] L3 import resources and project migration
To the distance we have been looking for -- film review of "flying house journey"
服务熔断 Hystrix
Under the national teacher qualification certificate in the first half of 2022
[sum of two numbers] 169 sum of two numbers II - enter an ordered array