Cod sursa(job #1783899)

Utilizator Mihai_PredaPreda Mihai Dragos Mihai_Preda Data 19 octombrie 2016 16:19:27
Problema Secventa 2 Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n, k;
int v[50001];

int s[50001];

const int INF = (1 << 30);

void citire()
{
    in >> n >> k;
    for(int i = 1; i <= n; ++i)
        in >> v[i];
}

void rezolvare()
{
    for(int i = 1; i <= n; ++i)
        s[i] = s[i-1] + v[i];

    int sMax = -INF;
    int inc, sf;
    for(int i = k; i <= n; ++i)
    {
        for(int j = i - k + 1; j >= 1; --j)
        {
            int sum = s[i] - s[j-1];
            if(sum > sMax)
            {
                sMax = sum;
                inc = j;
                sf = i;
            }
        }
    }
    out << inc << " " << sf << " " << sMax ;
}

int main()
{
    citire();
    rezolvare();
    return 0;
}