Pagini recente » Cod sursa (job #516972) | Cod sursa (job #1079136) | Cod sursa (job #1488042) | Cod sursa (job #2205314) | Cod sursa (job #1164006)
#include<fstream>
using namespace std;
ifstream in("buline.in");
ofstream out("buline.out");
const int nmax = 200006;
long v[nmax], n, sact, beg, bestbeg, bestend, smax = -10000000000, lung, lmax;
int main(){
int player_unu=0;
in>>n;
for(int i = 0 ; i<n; i++)
{
int aux;
in>>v[i]>>aux;
if(aux==0)
v[i] = -v[i];
}
for(int i = 0; i<n; i++)
{
if(sact<0)
{
beg = i;
sact = v[i];
lung = 1;
}
else{
sact += v[i];
lung++;
}
if(sact>smax || (sact==smax && beg<bestbeg) || (sact==smax && beg==bestbeg && lung>lmax))
{
smax = sact;
bestbeg = beg;
lmax = lung;
}
}
for(int i = 0; bestbeg>=i && sact>=0; i++)
{
sact += v[i];
lung++;
if(sact>smax)
{
smax = sact;
bestbeg = beg;
lmax = lung;
}
}
out<<smax<<" "<<bestbeg+1<<" "<<lmax<<'\n';
return player_unu;
}