Cod sursa(job #3203717)

Utilizator bajuuuuBajenaru Mihai Catalin Ionut bajuuuu Data 14 februarie 2024 12:06:53
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <map>
#include <iomanip>
#include <climits>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int v[6000001];
int sumapart[6000001];
int main()
{
    int n;
    cin >> n;
    for(int i =1; i<= n ; i++){
        cin >> v[i];
        v[i] = v[i]+v[i-1];
    }
    int minimum = 9999999;
    int indicemin = 9999999;
    int maximum = 0;
    int indicemax = 0;
    for(int i =1; i<= n ; i++){
      if ( v[i] < minimum){
        minimum = v[i];
        indicemin = i;
      }
      if (v[i]-minimum > maximum){
        maximum = v[i]-minimum;
        indicemax = i;
      }
    }
   cout << maximum << ' ' << indicemin+1 << ' ' << indicemax;
}