题解 | 小红的岁晚可可塔

小红的岁晚可可塔

https://www.nowcoder.com/practice/6b06f501f8154f57801590ca495f37ac

#include <iostream>
#include<vector>
using namespace std;

int main() {
    int n;
    cin>>n;
    vector<int> a(n) ;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    long long max =a[0];
    long long cut =a[0];
    for(int j=1;j<n;j++){
        if(cut+a[j]>a[j]){
            cut=cut+a[j];
        }
        else{
            cut=a[j];
        }
        if(cut>max){
            max=cut;
        }
    }
    cout<<max<<endl;
    return 0;
}

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务