Cod sursa(job #3300346)

Utilizator filipdanieloanFilip-Daniel Oancea filipdanieloan Data 14 iunie 2025 21:32:58
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.34 kb
#pragma GCC optimize("O2, unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>

#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define FOR(i, a, b) for(int i = (a); i < (b); i ++)
#define RFOR(i, a, b) for(int i = (a); i > (b); i --)

void fastIO(char input[50], char output[50])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    if(input != "std") {
        freopen(input, "r", stdin);
    }
    if(output != "std") {
        freopen(output, "w", stdout);
    }
}

int main()
{
    // fastIO("std", "std");
    fastIO("ssm.in", "ssm.out");
    
    int n;
    cin >> n;
    
    vi s(n, 0);
    
    int sMax = INT_MIN;
    int sCurent = 0;
    int stC = 0, stM = 0;
    int finM;
    
    FOR(i, 0, n) {
        cin >> s[i];
        
        if(sCurent + s[i] < s[i]) {
            sCurent = 0;
            stC = i;
        }
        sCurent += s[i];
        if(sMax < sCurent) {
            stM = stC;
            sMax = sCurent;
            finM = i;
        }
    }
    
    cout << sMax << ' ' << stM + 1 << ' ' << finM + 1;
    
    return 0;
}