Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #3344640)
#include <bits/stdc++.h>
using namespace std;
int n,s,sm,st,stm,drm,nsm;
vector<int>V;
int main()
{
ifstream in("buline.in");
ofstream out("buline.out");
in>>n;
V.push_back(-1);
for(int i=1,x,y;i<=n;i++)
{
in>>x>>y;
if(y==0)x=x*(-1);
V.push_back(x);
if(s<0){
s=0;
st=i;
}
s+=x;
if(s>sm){sm=s;stm=st,drm=i;}
}
s=0;
for(int i=1;i<st;i++)
{
s+=V[i];
if(s>nsm){
st=i;
nsm=s;
}
}
if(nsm<=0)
{
out<<sm<<" "<<stm<<" "<<drm-stm+1;
}
else{
out<<sm+nsm<<" "<<"0"<<" "<<drm+st-stm+1;
}
return 0;
}