Pagini recente » Cod sursa (job #2239094) | Cod sursa (job #2658127) | Cod sursa (job #389180) | Cod sursa (job #3179778) | Cod sursa (job #3167217)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
struct answer{
int value;
int left;
int right;
friend ostream& operator<<(ostream& os, answer& ans){
os<<ans.value<<' '<<ans.left<<' '<<ans.right;
return os;
}
} ans = {INT_MIN, 0, 0};
int n,x;
vector<int> s;
int main()
{
fin>>n;
fin>>x;
s.push_back(x);
int left;
for(int i = 2; i<=n; i++){
fin>>x;
if(s.back() + x > x)
s.push_back(s.back() + x);
else
left = i, s.push_back(x);
if(s.back() > ans.value)
ans = {s.back(), left, i};
}
fout<<ans;
return 0;
}