Pagini recente » Cod sursa (job #2705602) | Cod sursa (job #1691100) | Rating Sus Amogus (7h35up3rPr0) | Cod sursa (job #2705468) | Cod sursa (job #1703095)
#include <fstream>
using namespace std;
ifstream in ("ssm.in");
ofstream out ("ssm.out");
int main()
{
int n, i, a[6000010], S = 0, poz1,poz , poz1max = 1, poz2max = 1, k = 0;
in >> n;
for (i = 1; i <= n; i ++)
in >> a[i];
poz1 = 1;
int Smax = a[1];
for (i = 1; i <= n; i ++)
{
S = S + a[i];
if(a[i] > Smax) {
Smax = a[i];
poz1max = poz2max = i;
}
if(S > Smax) {
Smax = S;
poz1max = poz1;
poz2max = i;
}
if(S < 0) {
S = 0;
poz1 = i + 1;
}
}
out << Smax << " " << poz1max << " " << poz2max;
return 0;
}