Cod sursa(job #2811798)

Utilizator AlexandruBenescuAlexandru Benescu AlexandruBenescu Data 3 decembrie 2021 09:02:38
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <bits/stdc++.h>
#define L 1000000000000000000
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main(){
  int n, i, i1, i2, _i1;
  long long x, s, smax;
  fin >> n;
  smax = s = -L;
  _i1 = 1;
  for (i = 0; i < n; i++){
    fin >> x;
    if (s < 0){
      s = x;
      _i1 = i + 1;
    }
    else
      s = s + x;
    if (smax < s){
      smax = s;
      i2 = i + 1;
      i1 = _i1;
    }
  }
  fout << smax << " " << i1 << " " << i2 << "\n";
  return 0;
}