Cod sursa(job #2642950)

Utilizator Ionut2791Voicila Ionut Marius Ionut2791 Data 17 august 2020 20:38:49
Problema Secventa 2 Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int n, k, nr, v[50005];

int main(){
    ifstream fin("secv2.in");
    ofstream fout("secv2.out");
    fin >> n >> k;


    int maxx, posMax, minn, posMin;
    for(int i = 1; i <= n; ++i){
        fin >> nr;
        v[i] += v[i-1] + nr;
        if(maxx < v[i]){
            maxx = v[i];
            posMax = i;
        }
        if(minn > v[i]){
            minn = v[i];
            posMin = i+1;
        }
    }

    fout << posMin << " " << posMax << " " << v[posMax] - v[posMin-1];




    return 0;
}