Cod sursa(job #3195592)

Utilizator SimifilLavrente Simion Simifil Data 21 ianuarie 2024 12:52:56
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int main()
{
    int n;
    long long summax = 0;
    f >> n;
    int v;
    long long s = 0;
    int st = 1, dr = 1;
    int stmax, drmax;
    for( int i = 1; i <= n; ++i )
    {
      f >> v;
      if( s < 0 )
      {
        s = v;
        st = i;
        dr = i;
      }
      else
      {
        s = s+v;
        dr = i;
      }
      if( summax < s )
      {
        summax = s;
        stmax = st;
        drmax = dr;
      }
    }
    g << summax << " " << stmax << " " << drmax << " ";
    return 0;
}