Pagini recente » Cod sursa (job #3140800) | Cod sursa (job #1707747) | Cod sursa (job #467063) | Cod sursa (job #584375) | Cod sursa (job #3287263)
#include <fstream>
using namespace std;
ifstream in("buline.in");
ofstream out("buline.out");
const int sizee = 200000;
int n, val, type, v[2 * sizee + 2];
int summy, smax, __lf, lf, rg;
int main(){
in>>n;
for(int i = 1; i <= n; i++){
in>>val>>type;
v[i] = val * (type ? 1 : -1);
v[n + i] = v[i];
}
for(int i = 1; i <= 2 * n; i++){
summy += v[i];
if(summy < 0 || i - n == lf){
__lf = i + 1;
summy = 0;
}
if(summy > smax){
lf = __lf;
rg = i;
smax = summy;
}
}
out<<smax<<" "<<lf<<" "<<rg - lf + 1<<"\n";
return 0;
}