Cod sursa(job #2358461)

Utilizator riordache58Razvan Iordache riordache58 Data 28 februarie 2019 09:25:56
Problema Secventa 2 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>
#include <fstream>

using namespace std;

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

long long int i , i1 , max1 = -2100000 , x , pozi ;
long long int pozj , suma = -1 , sumax , n , k ;

int main()
{
    f >> n >> k;

    for ( i = 1 ; i <= n ; i ++ )
    {
        f >> x;

        if ( suma >= 0 )
            suma += x;

        else
        {
            i1 = i;
            suma = x;
        }

        if ( suma > max1 && i - i1 + 1 >= k )
        {
            max1 = suma;
            pozi = i1;
            pozj = i;
        }
        sumax += x;
    }
    if ( k == n)
        g << 1 << " " << n << " " << sumax;

    else
        g << pozi << " " << pozj << " " << max1;

    return 0;
}