Cod sursa(job #2277254)

Utilizator BotzkiBotzki Botzki Data 5 noiembrie 2018 21:55:03
Problema Secventa Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <fstream>
#include <deque>
#include <string>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
const int NMAX=500000;
int v[NMAX+5];
deque<int>q;
string s;
int main()
{
    int n, i, k, el_max, pozi, pozf, aux=1, t;
    el_max=-2000000000;
    fin>>n>>k;
    fin.get();
    getline(fin, s);
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='-')
        {
            t=0;
            i++;
            while(s[i]>='0' and s[i]<='9')
            {
                t=t*10+(s[i]-'0');
                i++;
            }
            v[aux]=0-t;
            aux++;
            i--;
            continue;

        }
        if(s[i]>='0' and s[i]<='9')
        {
            t=0;
            while(s[i]>='0' and s[i]<='9')
            {
                t=t*10+(s[i]-'0');
                i++;
            }
            i--;
            v[aux]=t;
            aux++;
            continue;
        }

    }
    for(i=1;i<=n;i++)
    {
        while(!q.empty() and v[i]<=v[q.back()])
            q.pop_back();
        q.push_back(i);
        if(i-k==q.front())
           q.pop_front();
        if(i>=k and v[q.front()]>el_max)
        {
           el_max=v[q.front()];
           pozi=i-k+1;
           pozf=i;
        }
    }
    fout<<pozi<<" "<<pozf<<" "<<el_max<<"\n";
    return 0;
}