Cod sursa(job #2720599)

Utilizator darkeagleDaniel Popescu darkeagle Data 11 martie 2021 00:52:13
Problema Secventa 2 Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;

int k, n;
int v[50001];
int a[50001];
int b[50001];
int main()
{

    freopen("secv2.in","r", stdin);
    freopen("secv2.out","w", stdout);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> v[i];

a[1] = v[1];
for(int i = 2; i <= n; i++)
    a[i] = a[i - 1] + v[i];
int max1 = a[1];
int p1, p2;
for(int i = 0; i <= n - 1; i++)
{
    for(int j = i + 1; j <= n; j++) {
        if(max1 < a[j] - a[i])
        {
            max1 = a[j] - a[i];
            p1 = j;
            p2 = i;
        }
    }
}
  cout << p2 + 1 << " " << p1 << " " << max1;
    return 0;
}