Cod sursa(job #2048655)
Utilizator | Data | 26 octombrie 2017 13:51:57 | |
---|---|---|---|
Problema | Buline | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 2.05 kb |
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
ifstream fin("buline.in");
ofstream fout("buline.out");
int n, v[200001], d[200001], i, lmax, lmin, maxim, minim, pozmin, pozmax, ok, l, poz;
bool c;
long long s;
int main(){
fin>>n;
for(i=1; i<=n; i++){
fin>>v[i]>>c;
if( c==0 )
v[i]*=(-1);
s+=v[i];
}
ok=0;
for( i=1; i<=n; i++){
if( d[i-1]<=0 || i==1){
d[i] = v[i];
l = 1;
poz=i;
}else{
d[i] = d[i-1] + v[i];
l++;
}
if(ok == 0){
maxim = d[i];
pozmax=poz;
lmax=l;
ok=1;
}
if( maxim < d[i]){
maxim = d[i];
lmax = l;
pozmax = poz;
}
}
ok=0;
for( i=1; i<=n; i++){
if( d[i-1]>=0 || i==1){
d[i] = v[i];
l=1;
}else{
d[i] = d[i-1] + v[i];
l++;
}
if( ok==0 ){
minim = d[i];
lmin = l;
pozmin = i;
ok=1;
}
if( minim > d[i]){
minim = d[i];
pozmin = i;
lmin = l;
}
}
if ( maxim > s-minim)
fout<<maxim<<" "<<pozmax<<" "<<lmax;
else
fout<<s-minim<<" "<<pozmin+1<<" "<<n-lmin;
return 0;
}