#include <iostream>
#include<cstring>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
int n;cin >>n;
int a[n];
int i=0,j=0,t=0,m=0,p=0,q=0,y=0,l=0;
for(i=0;i<n;i++)
cin >>a[i];
for(i=0;i<n;i++){
t+=a[i];
if(t>m){
m=t;
p=i;
}
else if(t<0)
t=0;
if(a[i]<0)
y++;
if(a[i]==0)
l++;
}
if(y+l==n&&y!=n)
cout <<"0"<<" "<<"0"<<" "<<"0";
else if(y==n)
cout <<"0"<<" "<<a[0]<<" "<<a[n-1];
else if(y!=n){
cout <<m<<" ";
for(j=p;;j--){
q+=a[j];
if(q==m&&p!=0){
if(a[j-1]!=0){
cout <<a[j]<<" "<<a[p];
break;
}
else if(a[j-1]==0){
cout <<"0"<<" "<<a[p];
break;
}
}
else if(q==m&&p==0){
cout <<a[0]<<" "<<a[0];
break;
}
}
}
}
24分
最大列前面为0
一个测试点错了
最大列前面为0;思路是我检测a[j-1],如果它不等于0,在p == m的情况下它肯定为负,直接舍去。若它等于0,在p==m的情况下,我不用管它前面有多少个0,直接输出【和 0 列尾】就好,我也不知道哪里错了。
以后再改吧。
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务