Cod sursa(job #2403461)

Utilizator tomaionutIDorando tomaionut Data 11 aprilie 2019 16:28:25
Problema Secventa 2 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("secv2.in");
ofstream fout("secv2.out");
int n,k;
int a[50005];
int main()
{
   int i,j=0,imax,jmax,s=INT_MIN;
   fin >> n >> k;
   for (i=1; i<=n; i++)
    fin >> a[i];
   for (i=1; i<=n; i++)
    a[i]+=a[i-1];
   for (i=k; i<=n; i++)
   {
       if (a[j]>a[i-k]) j=i-k;
       if (a[i]-a[j]>s)
       {
           s=a[i]-a[j];
           imax=i;
           jmax=j+1;
       }
   }
    fout << jmax << " " << imax << " " << s << "\n";



    return 0;
}