Cod sursa(job #2618864)

Utilizator KillHorizon23Orban Robert KillHorizon23 Data 26 mai 2020 14:18:22
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.26 kb
#include<bits/stdc++.h>
//#define console
using namespace std;
#define pb push_back
#define mp make_pair
#define siz(x) ((int)(x).size())
#define full(v) v.begin(), v.end()
#ifndef console
      ifstream fin("ssm.in");
      ofstream fout("ssm.out");
      #else
            #define fin cin
            #define fout cout
#endif
#define MAX(x, y) ((a) > (b) ? (a) : (b))
#define usain_bolt() (ios_base::sync_with_stdio(false), \
                      fin.tie(NULL), fout.tie(NULL))
const int oo = (1 << 30);
const double PI = acos(-1);

const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

typedef long long ll;
typedef unsigned int ui;


int main()
{
    usain_bolt();
    int n;
    fin >> n;
    vector<int> v(n + 5);
    for (int i = 1; i <= n; ++i)
            fin >> v[i];
    int maxx = INT_MIN, st, start, finish, s = -1;
    start = finish = 0;
    for (int i = 1; i <= n; ++i)
    {
          if (s < 0) s = 0, st = i;
          s += v[i];
          if (s >= maxx) maxx = s, start = st, finish = i;
    }
    fout << maxx << " ";
    fout << start << " " << finish;
#ifndef console
      fin.close(), fout.close();
      #else
            #undef fin cin
            #undef fout cout
#endif // console
    return 0;
}