Cod sursa(job #2922695)

Utilizator tallianfranciskaFranciska Tallian tallianfranciska Data 9 septembrie 2022 17:55:45
Problema Subsecventa de suma maxima Scor 65
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.71 kb
// ssm.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <fstream>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;
ifstream cin("ssm.in");
ofstream cout("ssm.out");
vector<long long>x;
vector<pair<long long, int>>y;
long long i, n;
struct maxim
{
    long long ertek,kezd, veg;
};
int main()
{
    cin >> n;
    x.resize(n + 1);
    y.resize(n + 1);

    for (i = 1; i <= n; ++i)
    {
        cin >> x[i];
    }
  maxim maxi = { LLONG_MIN,0,0 };
    for (i = 1; i <= n; ++i)
    {
        if (y[i - 1].first + x[i] > x[i])
        {
            y[i].first = y[i - 1].first + x[i];
            y[i].second = y[i - 1].second;
        }
        else
        {
            y[i].second = i;
            y[i].first = x[i];
        }
        if (maxi.ertek < y[i].first)
        {
            maxi.ertek = y[i].first;
            maxi.kezd = y[i].second;
            maxi.veg = i;
       }
    }
    cout << maxi.ertek <<" "<< maxi.kezd << " " << maxi.veg;

    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file