Pagini recente » Diferente pentru utilizator/pasparan intre reviziile 2 si 1 | Monitorul de evaluare | Monitorul de evaluare | Atasamentele paginii Profil mariusn | Cod sursa (job #3332509)
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin("buline.in");
ofstream fout("buline.out");
const int NMAX = 1e5 * 2 + 2;
int n, v[NMAX], sumtot = 0;
signed main()
{
fin >> n;
for(int i = 1; i <= n; i++)
{
int x, y;
fin >> x >> y;
v[i] = y ? x : x * (-1);
sumtot += v[i];
}
int l = 1, r = 1, curl = 1, max = v[1], curmax = v[1];
for(int i = 2; i <= n; i++)
{
if(curmax + v[i] > v[i])
{
curmax += v[i];
}
else{
curmax = v[i];
curl = i;
}
if(curmax > max)
{
max = curmax;
l = curl;
r = i;
}
}
int ans = max, lf = l, rf = r, len = r - l + 1;
l = 1, r = 1, curl = 1, max = v[1], curmax = v[1];
for(int i = 2; i <= n; i++)
{
if(curmax + v[i] < v[i])
{
curmax += v[i];
}
else{
curmax = v[i];
curl = i;
}
if(curmax < max)
{
max = curmax;
l = curl;
r = i;
}
}
max = sumtot - max;
if(max > ans)
{
ans = max;
lf = r + 1;
len = n - (r - l + 1);
}
fout << ans << " " << lf << " " << len;
return 0;
}