Cod sursa(job #3195919)

Utilizator AndreiMLCChesauan Andrei AndreiMLC Data 22 ianuarie 2024 09:32:42
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

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

int n;
const int nmax = 6000005;
int v[nmax];
long long cost[nmax];
int cost_max=INT_MIN;
int ind_start;
int ind_stop;
int main()
{
    f >> n;
    for(int i = 1;i<=n;i++)
    {
        f >> v[i];
        cost[i] = v[i] + cost[i-1];
    }
    int st=1,dr=n;
    for(int i = 1;i<=n;i++)
    {
        for(int j = i+1;j<=n;j++)
        {
            if(cost[j] - cost[i] + v[i] > cost_max)
            {
                cost_max = cost[j] - cost[i] + v[i];
                ind_start = i;
                ind_stop = j;
            }
        }
    }
    g << cost_max << '\n' << ind_start << ' ' << ind_stop;
    return 0;
}