Pagini recente » Cod sursa (job #3211499) | Cod sursa (job #2329120) | Cod sursa (job #2594282) | Cod sursa (job #3218229) | Cod sursa (job #1491964)
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream f("buline.in");
ofstream g("buline.out");
int n, s, i, l, smax, lmax, imax, x;
int v[200005];
f >> n;
f >> v[1] >> x;
if (x == 0)
v[1] *= (-1);
smax = s = v[1];
l = i = imax = lmax = 1;
for (int j = 2; j <= n; ++j){
f >> v[j] >> x;
if (x == 0)
v[j] *= (-1);
if (s < 0){
s = v[j];
i = j;
l = 1;
}
else{
s += v[j];
l++;
}
if (s > smax){
smax = s;
imax = i;
lmax = l;
}
}
if (s > 0)
for (int j = 1; j < i && s > 0; ++j){
s += v[j];
l++;
if (s > smax){
smax = s;
imax = i;
lmax = l;
}
}
g << smax << " " << imax << " " << lmax;
f.close();
g.close();
return 0;
}