• P1115-最大子段和


     1 #include <bits/stdc++.h>
     2 #define _for(i,a,b) for(int i = (a);i < b;i ++)
     3 typedef long long ll;
     4 using namespace std;
     5 int n;
     6 inline ll read()
     7 {
     8     ll ans = 0;
     9     char ch = getchar(), last = ' ';
    10     while(!isdigit(ch)) last = ch, ch = getchar();
    11     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
    12     if(last == '-') ans = -ans;
    13     return ans;
    14 }
    15 inline void write(ll x)
    16 {
    17     if(x < 0) x = -x, putchar('-');
    18     if(x >= 10) write(x / 10);
    19     putchar(x % 10 + '0');
    20 }
    21 int a[200039];
    22 
    23 int main()
    24 {
    25     n = read();
    26     _for(i,0,n)
    27         a[i] = read();
    28     
    29     int rnt = a[0];
    30     int trnt = a[0];
    31     _for(i,1,n)
    32     {
    33         if(trnt<0)
    34             trnt = a[i];
    35         else
    36             trnt += a[i];
    37         rnt = max(rnt,trnt);
    38     }
    39     write(rnt);
    40     return 0;
    41 }
  • 相关阅读:
    Tarjan 算法 自学整理
    POJ 2395 Out of Hay
    Codevs 1557 热浪
    Codevs 2956 排队问题
    Codevs 1005 生日礼物
    集合
    奇怪的函数
    关押罪犯
    搭积木
    大数据
  • 原文地址:https://www.cnblogs.com/Asurudo/p/11284579.html
Copyright © 2020-2023  润新知