Pagini recente » Cod sursa (job #1256479) | Cod sursa (job #2418374) | Cod sursa (job #2603833) | Cod sursa (job #1335457) | 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;
}