Pagini recente » Cod sursa (job #931196) | Cod sursa (job #1151518) | Cod sursa (job #1082538) | Cod sursa (job #2629158) | Cod sursa (job #1044249)
#include<fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
#define maxn 6000005
unsigned long long N, pmax=1, v[maxn], before[maxn];
int main()
{
f >> N;
f >> v[1];
before[1] = 1;
for (int i = 2; i <= N; ++i) {
f >> v[i];
if (v[i - 1] < 0) {
before[i] = i;
pmax = (v[i] > v[pmax]) ? i : pmax;
}
else if (v[i] + v[i - 1] > v[pmax])
pmax = i;
if (v[i] + v[i-1] > 0)
v[i] += v[i - 1], before[i] = before[i - 1];
}
g << v[pmax] << ' ' << before[pmax] << ' ' << pmax;
return 0;
}