Cod sursa(job #2344789)

Utilizator GoogalAbabei Daniel Googal Data 15 februarie 2019 17:13:30
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in("ssm.in");
ofstream out("ssm.out");

const int INF = 2147482600;

int n;
int smax = -INF;
int umax, pmax;
int sc, pc;

int main()
{
  in >> n;
  for(int i = 1; i <= n; i++) {
    int x;
    in >> x;

    if(sc < 0) {
      sc = 0;
      pc = i;
    }

    sc += x;

    if(sc > smax) {
      smax = sc;
      pmax = pc;

      umax = i;
    }
  }

  out << smax << ' ' << pmax << ' ' << umax << '\n';

  in.close();
  out.close();

  return 0;
}