Mai intai trebuie sa te autentifici.

Cod sursa(job #1150938)

Utilizator cristinamateiCristina Matei cristinamatei Data 23 martie 2014 18:41:05
Problema Secventa 2 Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>

using namespace std;

int v[50001], sum[50001];

int main()
{
    ifstream in("secv2.in");
    ofstream out("secv2.out");
    int n, k, i, sc = 0, stc = 1, smax, stmax, drmax;
    in >> n >> k;
    for ( i = 1; i <= n; i++ )
    {
        in >> v[i];
        sum[i] = sum[i-1] + v[i];
    }
    smax = sum[k];
    stmax = 1;
    drmax = k;
    for ( i = 1; i <= n; i++ )
    {
        if ( sc < sum[i] )
        {
            sc = 0;
            stc = i;
        }
        sc = sum[i] - sum[stc];
        if ( sc > smax && i-stc >= k)
        {
            smax = sc;
            stmax = stc;
            drmax = i;
        }
    }
    out << stmax<<' '<< drmax << ' '<< smax;
    return 0;
}