Pagini recente » Profil M@2Te4i | Statistici Gau Gau (Gau_Gau) | Profil M@2Te4i | Monitorul de evaluare | Cod sursa (job #1551148)
#include <fstream>
#include <deque>
#include <algorithm>
using namespace std;
int main()
{
int N, i, x, y, v[200001], startIndex = 1, s = 0, smax = - (1 << 30), startPosition = 0, length = 0;
deque<int> dq;
ifstream f("buline.in");
f >> N;
for (i = 0; i < N; i++)
{
f >> x >> y;
v[i] = y == 1 ? x : -x;
v[i + N] = v[i];
}
f.close();
for (i = 1; i < 2*N - 1; i++)
{
if (v[i - 1] + v[i] > v[i])
{
v[i] = v[i - 1] + v[i];
}
else
{
startIndex = i;
}
if (v[i] > smax)
{
smax = v[i];
length = (i - startIndex) + 1;
}
}
ofstream g("buline.out");
g << smax << " " << startIndex + 1 << " " << length;
g.close();
return 0;
}