Pagini recente » Cod sursa (job #1532778) | Cod sursa (job #2395277) | Cod sursa (job #3126265) | Cod sursa (job #294181) | Cod sursa (job #2930430)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("buline.in");
ofstream fout("buline.out");
int main()
{
int n;
fin >> n;
vector<int> v(2 * n + 7);
for(int i = 1; i <= n; i++)
{
int x, type;
fin >> x >> type;
v[i] = v[i + n] = x * (type == 0 ? -1 : 1);
}
deque<int> q;
q.push_back(1);
int smax = v[1];
int pmax = 1;
int lmax = 1;
for(int i = 2; i <= 2 * n; i++)
{
v[i] += v[i - 1];
while(!q.empty() && i - q.front() > n)
q.pop_front();
if(v[i] - v[q.front()] > smax)
{
smax = v[i] - v[q.front()];
pmax = q.front() + 1;
lmax = i - q.front();
}
while(!q.empty() && v[q.back()] > v[i])
q.pop_back();
q.push_back(i);
}
fout << smax << " " << pmax << " " << lmax;
return 0;
}