Pagini recente » Cod sursa (job #1613055) | Cod sursa (job #654902) | Cod sursa (job #2113217) | Cod sursa (job #2726670) | Cod sursa (job #2444597)
#include <bits/stdc++.h>
#define BUFFER_SIZE 1 << 17
char buffer[BUFFER_SIZE];
int pos = BUFFER_SIZE;
inline char next() {
if (pos == BUFFER_SIZE) {
fread(buffer, 1, BUFFER_SIZE, stdin);
pos = 0;
}
return buffer[pos++];
}
inline int read() {
int x = 0, neg = 1;
char c = next();
if (c == '-') {
neg = -1;
}
while (!('0' <= c && c <= '9')) {
c = next();
}
while ('0' <= c && c <= '9') {
x = (x << 3) + (x << 1) + (c - '0');
c = next();
}
return x * neg;
}
int main() {
freopen("ssm.in", "r", stdin);
freopen("ssm.out", "w", stdout);
int n;
n = read();
int dp, init_pos, starting_pos, last_pos, sum = 0, max_sum = INT_MIN;
for (int i = 0 ; i < n ; ++i) {
dp = read();
if (sum >= 0) {
sum += dp;
} else {
sum = dp;
init_pos = i;
}
if (max_sum < sum) {
max_sum = sum;
starting_pos = init_pos;
last_pos = i;
}
}
printf("%d %d %d\n", max_sum, starting_pos + 1, last_pos + 1);
return 0;
}