Cod sursa(job #3145993)

Utilizator leelcheeseCiovnicu Denis leelcheese Data 17 august 2023 19:06:32
Problema Secventa 2 Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nmax 50005
#define MOD 666013         
#define INF 1000000007
//#define fin cin
//#define fout cout

ifstream fin("secv2.in");
ofstream fout("secv2.out");

int n, k;
int a[nmax];

int main()
{
    int i, j, maxi, x, y;
    fin >> n >> k;
    for (i = 1; i <= n; i++)
    {
        fin >> a[i];
        a[i] += a[i - 1];
    }
    maxi = -INF;
    for (i = 1; i <= n - 2; i++)
        for (j = i + 2; j <= n; j++)
            if (a[j] - a[i - 1] > maxi)
            {
                maxi = a[j] - a[i - 1];
                x = i;
                y = j;
            }
    fout << x << " " << y << " " << maxi << "\n";
    fout.close();
    fin.close();
    return 0;
}