Pagini recente » Cod sursa (job #379202) | Cod sursa (job #1421462) | Cod sursa (job #3160267) | Cod sursa (job #3168647) | Cod sursa (job #3287264)
#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];
int64_t summy, smax = -(1 << 30);
int __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;
}