#include <vector> #include<iostream> using namespace std; int main() { int k; cin>>k; int left_index=0,right_index=k-1,sum=-1,tmp=0,tmp_index=0; vector <int> num(k); for(int i=0;i<k;i++) { cin>>num[i]; tmp+=num[i]; if(tmp<0) { tmp=0; tmp_index=i+1; } else if(tmp>sum) { sum=tmp; left_index=tmp_index; right_index=i; } } if(sum<0) sum=0; cout<<sum<<" "<<num[left_index]<<" "<<num[right_index]<<endl; return 0; }
https://blog.csdn.net/TOBEALISTENNER/article/details/86667721
原文地址:https://www.cnblogs.com/QRain/p/12284488.html
时间: 2024-10-10 12:48:51