Cod sursa(job #1106570)

Utilizator AeroHHorea Stefan AeroH Data 12 februarie 2014 21:52:27
Problema Secventa Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <fstream>
#include <deque>
#include <string>
#include <cstring>
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
FILE*fin=fopen("secventa.in","r");
int i,j,k,N,M,D,a,b,X,Y,rasp=-1<<30;
deque <int> mini,maxi;
int v[500005];
char s[5000001],c;
int main()
{
   fscanf(fin,"%d%d%c",&N,&D,&c);
   fgets(s,5000001,fin);
   int pos=0,semn;
   for (i=1;i<=N;++i)
        {
            if (s[pos]=='-')semn=-1,++pos;else semn=1;
            while(isdigit(s[pos]))v[i]=v[i]*10+s[pos]-'0',++pos;v[i]*=semn;++pos;

            while (mini.size()&&v[mini.back()]>v[i])
                mini.pop_back();
            mini.push_back(i);
            if (mini.front()==i-D)
                mini.pop_front();
            if (i>=D&&v[mini.front()]>rasp)
                {
                    X=i-D+1;
                    Y=i;
                    rasp=v[mini.front()];
                }
        }

    g<<X<<" "<<Y<<" "<<rasp;
   return 0;

}