Pagini recente » Cod sursa (job #1578475) | Cod sursa (job #2241475) | Cod sursa (job #2282496) | Cod sursa (job #1362828) | Cod sursa (job #1254329)
#include<fstream>
#include<iostream>
using namespace std;
ifstream in("buline.in");
ofstream out("buline.out");
int v[500009],n;
void citire()
{
in>>n;
int x,y;
for(int i = 1 ; i <= n ; i++){
in>>x>>y;
if(y == 0){
v[i] = -x;
}
else
v[i] = x;
}
int c = n;
for(int i = 1 ; i <= n ; i++)
v[++c] = v[i];
in.close();
}
int main()
{
citire();
int best = - 99999999,s = 1,lg,sum = 0,bg;
for(int i = 1 ; i <= 2*n ; i++){
if(sum < 0){
s = i;
sum = v[i];
}
else
sum += v[i];
if(sum > best && i-s+1 <= n){
best = sum;
bg = s;
lg = i-s+1;
}
}
out<<best<<" ";
if(bg > n)
out<<bg-n<<" ";
else
out<<bg<<" ";
out<<lg;
return 0;
}