当前位置:网站首页>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;
}
边栏推荐
- 被舆论盯上的蔚来,何时再次“起高楼”?
- Embedded database development programming (zero)
- [to be continued] [UE4 notes] L3 import resources and project migration
- cocos2dx_ Lua card flip
- [turn to] MySQL operation practice (III): table connection
- [turn]: OSGi specification in simple terms
- TF-A中的工具介绍
- The present is a gift from heaven -- a film review of the journey of the soul
- Cocos progress bar progresstimer
- Binary search basis
猜你喜欢
Fragment addition failed error lookup
Research on the value of background repeat of background tiling
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
Quick sort summary
Unity check whether the two objects have obstacles by ray
嵌入式数据库开发编程(零)
National teacher qualification examination in the first half of 2022
2022年上半年国家教师资格证考试
Use of snippets in vscode (code template)
[depth first search] 695 Maximum area of the island
随机推荐
To be continued] [UE4 notes] L4 object editing
Learning notes of "hands on learning in depth"
cocos_ Lua listview loads too much data
Kali 2018 full image download
Simple HelloWorld color change
Solon Logging 插件的添加器级别控制和日志器的级别控制
Unity synergy
用 Jmeter 工具做个小型压力测试
A complete attack chain
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
Unity writes timetables (without UI)
Grail layout and double wing layout
Judge the position of the monster in the role under unity3d
Count sort
UE fantasy engine, project structure
Generate filled text and pictures
[leetcode] integer inversion [7]
BUUCTF MISC
Embedded database development programming (V) -- DQL
Vs2015 secret key