Pagini recente » Cod sursa (job #2492861) | Cod sursa (job #2594259) | Cod sursa (job #3175081) | Cod sursa (job #2375662) | Cod sursa (job #3165731)
#include <fstream>
#include <climits>
using namespace std;
ifstream cin("buline.in");
ofstream cout("buline.out");
int n,i,j,v[200009],st,s,Max=INT_MIN,st1,l,l1;
bool t;
int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>v[i]>>t;
if(!t)
v[i]*=(-1);
}
st=st1=1;
l1=0;
for(j=1;j<=2;j++)
{
for(i=1;i<=n;i++)
{
if(s+v[i]>=v[i])
s+=v[i],l1++;
else
s=v[i],st1=i,l1=1;
if(s>Max)
if(l1<n)
{
Max=s;
st=st1;
l=l1;
}
}
}
cout<<Max<<" "<<st<<" "<<l;
return 0;
}