Cod sursa(job #1078133)

Utilizator japjappedulapPotra Vlad japjappedulap Data 12 ianuarie 2014 01:06:14
Problema Secventa 2 Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>
#include <cstring>
using namespace std;

int n, k, x, s[50001], MIN = 2000000000, MAX = -2000000000, lf, rg;

void Read();
void Write();

int main()
{
    Read();
    Write();
    return 0;
}

void Write()
{
    for (int i = k; i <= n; ++i)
    {
        if (MIN > s[i-k])
            MIN = s[i-k], x = i-k;
        if (s[i]-MIN > MAX)
            MAX = s[i]-MIN, lf = x+1, rg = i;
    }
    ofstream os ("secv2.out");
    os << lf << ' ' << rg << ' ' << MAX;
    os.close();
};

void Read()
{
    ifstream is ("secv2.in");
    char Pars[400001], ax;
    bool bz = false;
    is >> n >> k; n = 1;
    is.get(ax); is.getline(Pars, 400000, EOF);
    is.close();
    for (int i = 0; i < strlen(Pars); ++i)
    {
        if (Pars[i] == '-') bz = true, ++i;
        while (isdigit(Pars[i]))
        {
            x += Pars[i]-48;x *= 10;
            ++i;
        }
        x /= 10;
        if (bz == true) x *= -1;
        s[n] = s[n-1] + x;   n++;
        bz = false;x = 0;
    }
    --n;
};