zoukankan      html  css  js  c++  java
  • 连续和最大

                                                                                       连续和最大
                      难度级别:B; 运行时间限制:1000ms; 运行空间限制:51200KB; 代码长度限制:2000000B
    试题描述
    给定一个整数序列a1、a2…an,求这个序列中的一个连续子序列,使得这个序列中的数的和最大。
    输入
    第一行,一个整数n。
    第二行,n个整数,a1、a2...an。
    输出
    一行,一个整数,表示你所求的最大的和。
    输入示例
    8
    3 -6 -8 4 7 -5 5 2
    输出示例
    13
    其他说明
    数据范围:N<=500000,序列中所有数的绝对值均不超过1000

     1 #include<iostream>
     2 using namespace std;
     3 int main()
     4 {
     5     long long n,i,s,a=0,b=0,c=0;
     6     cin>>n;
     7     for(i=0;i<n;i++)
     8     {
     9         scanf("%lld",&s);
    10         a+=s;
    11         if(a>b) b=a;
    12         if(b>c) c=b;
    13         if(a<=0)
    14         {
    15             a=0;
    16             b=0;
    17         }
    18     }
    19     printf("%lld",c);
    20 }
  • 相关阅读:
    JVM StackOverflowError vs. OutOfMemoryError
    db2 command line notes
    my emacs configuration
    repackage android application
    file -i haha.csv
    QualType in clang
    STM in Clojure
    32bit / 64bit co-exist Linux, ld-linux.so, linux-gate.so.1 etc
    hash tree
    K-S Test
  • 原文地址:https://www.cnblogs.com/LZHE/p/5684648.html
Copyright © 2011-2022 走看看