当前位置:网站首页>7-3 maximum sub segment and
7-3 maximum sub segment and
2022-06-24 23:31:00 【White -】
7-3 Maximum sub sum
Given n It's an integer ( It could be negative ) The sequence of components a[1],a[2],a[3],…,a[n], Find the sequence as a[i]+a[i+1]+…+a[j] The maximum value of the sum of the subsegments of . When all given integers are negative , Define sub segments and as 0.
The time complexity of the algorithm is required to be O(n).
Input format :
There are two lines of input :
The first line is n value (1<=n<=10000);
The second line is n It's an integer .
Output format :
Output maximum sub segment sum .
sample input :
Here's a set of inputs . for example :
6
-2 11 -4 13 -5 -2
sample output :
Here is the corresponding output . for example :
20
Code :
#include <stdio.h>
#include <stdlib.h>
int n;
int a[10100];
int vis[10100];
int findmax(int a,int b)
{
return a>=b?a:b;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int max1=0;
int temp;
for(int i=1;i<=n;i++)
{
if(temp>max1)
max1=temp;
if(temp<0)
temp=a[i];
else
temp+=a[i];
}
printf("%d",max1);
return 0;
}
202206222059 3、 ... and
边栏推荐
- throttle-debounce.js:一个小型的防抖节流函数库
- R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses exp function, confint function and coef function to obtain the confidence
- Laravel message queue
- 7-2 求解买股票问题
- R language uses GLM function to build Poisson log linear regression model, processes three-dimensional contingency table data to build saturation model, uses summary function to obtain model summary s
- 冒泡排序
- Common regular expressions
- InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
- 【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化
- 国内有哪些好的智能家居品牌支持homekit?
猜你喜欢

Pseudo original intelligent rewriting API Baidu - good collection

基于三维GIS开发的水电工程建设方案

What good smart home brands in China support homekit?

idea创建模块提示已存在

go 语言指针,值引用和指针引用

选择类排序法

伪原创智能改写api百度-收录良好
What you must know about time series database!

HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛

Volcano成Spark默认batch调度器
随机推荐
冒泡排序
UNION ALL UNION FULL JOIN
Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
从客户端到服务器
Laravel add helper file
372. chessboard coverage
国内有哪些好的智能家居品牌支持homekit?
QT to place the form in the lower right corner of the desktop
Harmonyos accessing database instances (3) -- use ORM bee to test how good harmonyos is
Use of laravel verifier
选择类排序法
Latest development of jetpack compose
【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化
(Smooth)ScrollToPosition doesn't work properly with RecyclerView
Laravel authentication module auth
基于三维GIS开发的水电工程建设方案
【js】-【树】-学习笔记
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the AIC function to compare the AIC values of the two models (simpl
js监听页面或元素scroll事件,滚动到底部或顶部
379. 捉迷藏