Cod sursa(job #3275217)

Utilizator tudorpisica@gmail.comPisica Tudor [email protected] Data 9 februarie 2025 14:31:32
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
#define nmax 6000001

int main()
{
ifstream cin("ssm.in");
ofstream cout("ssm.out"); 

int n, v[nmax],  st = 1 , dr = 1, smax = INT_MIN, sum = 0,drmax = 1;
for(int i = 1; i <= n; i++)
cin >> v[i];

smax = v[1];

for(int i = 1; i <= n; i++){
    if(smax + v[i] < v[i]){
        sum = v[i];
        st = i;
    }
    else
    sum += v[i];
    
    if(sum > smax){
        smax = sum;
        drmax = i;
    }
    
}

cout << smax << " " << st << " " << drmax;

    return 0;
}