Cod sursa(job #2617687)

Utilizator PopescuAndreiAlexandruPopescu Andrei Alexandru PopescuAndreiAlexandru Data 22 mai 2020 17:02:52
Problema Secventa 2 Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <fstream>
#include <deque>

using namespace std;

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

const long long INF = (1<<61);
const int DIM = 50005;

long long n,k,x,DP[DIM],pos,stx,sty,Max=-INF;

int main()
{
    fin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        fin>>x;
        DP[i]=DP[i-1]+x;
    }
    for(int i=k;i<=n;i++)
    {
        int ans=INF;
        for(int j=1;j<=i-k;j++)
        {
            if(DP[j]<ans)
            {
                ans=DP[j];
                pos=j;
            }
        }
        int sum=DP[i]-ans;
        if(sum>Max)
        {
            Max=sum;
            stx=pos+1;
            sty=i;
        }
    }
    fout<<stx<<" "<<sty<<" "<<Max<<'\n';
}