Cod sursa(job #2323992)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 20 ianuarie 2019 10:00:29
Problema Secventa 2 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
#include <climits>

using namespace std;

ifstream cin("secv2.in");
ofstream cout("secv2.out");

int main()
{
    int n, k;
    cin >> n >> k;

    int maxx = INT_MIN, dp = 0, st = 0, dr = 0;
    int stM = 0, drM = 0;
    for(int i = 1; i <= n; ++i)
    {
        int x;
        cin >> x;

        if(i == 1)
        {
            st = 1;
            dr = 1;
            dp = x;
            if(dp > maxx)
            {
                maxx = dp;
                stM = st;
                drM = dr;
            }
        }
        else
        {
            if(dp + x < x)
            {
                dp = x;
                st = i;
                dr = i;
            }
            else
            {
                dr = i;
                dp = dp + x;
            }
            if(dp > maxx && dr - st + 1 >= k)
            {
                maxx = dp;
                stM = st;
                drM = dr;
            }
        }
    }
    cout << stM << ' '  << drM << ' ' << maxx << ' ' << '\n';
    return 0;
}