Cod sursa(job #3277837)

Utilizator tudorpisica@gmail.comPisica Tudor [email protected] Data 17 februarie 2025 15:02:06
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <bits/stdc++.h>

using namespace std;

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

int main()
{
    int sc_i = 0, st = 1, st_max = 1, dr_max = 1, s_max = INT_MIN;
  
    int n, x;
    
    fin >> n;
    
    for(int i = 1; i <= n; i++) {
        fin >> x;
        
        if (x > sc_i + x) {
            sc_i = x;
            st = i;
        } else 
            sc_i += x;
            
        if (sc_i > s_max) {
            s_max = sc_i;
            st_max = st;
            dr_max = i;
        }
    }
    
    g << s_max << " " << st_max << " " << dr_max;