Cod sursa(job #2632006)

Utilizator eugen5092eugen barbulescu eugen5092 Data 1 iulie 2020 20:42:48
Problema Subsecventa de suma maxima Scor 75
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <bits/stdc++.h>
using namespace std;
#define inf 2000000000
ifstream ci("ssm.in");
ofstream cou("ssm.out");

int n;
int v[6000005];
void citire(){
    int i;
    ci>>n;
    for(i=1;i<=n;i++){
        ci>>v[i];
    }
}

void rez(){
    int mn=inf,mx=-inf,imn=0,imx=0;
    int smcr=0;
    for(int i=1;i<=n;i++){
        smcr+=v[i];
        if(smcr<mn){
            mn=smcr;
            imn=i;
        }
        if(smcr>mx){
            mx=smcr;
            imx=i;
        }
    }
    cou<<mx-mn<<" "<<imn+1<<" "<<imx;
}

int main()
{
    citire();
    rez();
    return 0;
}