Pagini recente » Cod sursa (job #2172697) | Cod sursa (job #595) | Cod sursa (job #1708578) | Cod sursa (job #1804594) | Cod sursa (job #3248786)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("buline.in");
ofstream fout("buline.out");
int n, x, semn, poz, lmax, smax = -1e9;
queue<int> q;
int main(){
fin >> n;
for(int i = 1; i <= n; ++i){
fin >> x >> semn;
if(!semn)
x = -x;
q.push(x);
}
int istart = 1, s = 0, len = 1;
for(int i = 1; i <= 2 * n; ++i){
x = q.front();
q.pop();
q.push(x);
s += x;
if(s > smax or (s == smax and istart < poz) or (s == smax and istart == poz and len < lmax)){
poz = istart;
smax = s;
lmax = len;
}
if(s < 0 or len > n){
s = 0;
len = 1;
istart = i + 1;
}
else{
++len;
}
}
if(s > smax or (s == smax and istart < poz) or (s == smax and istart == poz and len < lmax)){
poz = istart;
smax = s;
lmax = len;
}
fout << smax << ' ' << poz << ' ' << len;
}