Pagini recente » Cod sursa (job #1260033) | Cod sursa (job #1294577) | Cod sursa (job #524772) | Cod sursa (job #206726) | Cod sursa (job #2257651)
#include <bits/stdc++.h>
#include <climits>
#define inf (int)(INT_MAX-1)
std::ifstream InFile("ssm.in");
std::ofstream OutFile("ssm.out");
int indStart = 1, indEnd,
Max = -inf, Best = -inf;
void DP() {
int N, x, i = 0; InFile >> N;
indEnd = N;
while(N--) {
i++;
InFile >> x;
if(x > Best+x) {
indStart = i;
Best = x;
}
else Best = Best+x;
if(Best > Max) {
indEnd = i;
Max = Best;
}
} OutFile << Max << ' ' << indStart << ' ' << indEnd << '\n';
}
int main()
{
DP();
return 0;
}