Pagini recente » Cod sursa (job #3289109) | Cod sursa (job #2309206) | Cod sursa (job #2918207) | Cod sursa (job #368451) | Cod sursa (job #3195552)
#include <bits/stdc++.h>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
#ifndef ACASA
InParser in("ssm.in");
ofstream out("ssm.out");
#define cin in
#define cout out
#endif
int main()
{
#ifdef ACASA
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif
int n, sum = 0, start = 1, x, st, dr, max1 = INT_MIN;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> x;
if(sum < 0)
{
sum = 0;
start = i;
}
sum += x;
if(sum > max1)
{
max1 = sum;
st = start;
dr = i;
}
}
cout << max1 << " " << st << " " << dr;
return 0;
}