Cod sursa(job #1387214)

Utilizator azkabancont-vechi azkaban Data 13 martie 2015 20:12:12
Problema Secventa Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h>
#define Nmax 500013
using namespace std;
deque <int> Dq;
int i,n,aux,k,maxim(-1<<15),sol1;
int A[500013]; 
char buffer[10*Nmax];
int main()
{
 FILE *cin = fopen("secventa.in","r");
 ofstream cout("secventa.out");
 fscanf(cin,"%d%d\n",&n,&k);
 fgets(buffer,10*Nmax,cin);
 int semn(1),aux(0),i(0);
 long long size=strlen(buffer);
 for(int j=0;j<size;++j)
    {
     if(buffer[j] == '-') semn=-1;
              else
     if(buffer[j] != ' ') aux=aux*10+buffer[j]-'0';
     if(buffer[j] == ' ' || buffer[j] == '\n')
           {
           A[++i]=aux*semn;
           aux=0;
           semn=1;
           }
                          
    while(!Dq.empty() && A[i]<=A[Dq.back()]) Dq.pop_back();
    Dq.push_back(i);
    if (!Dq.empty() && i-k>=Dq.front()) Dq.pop_front();
    if (maxim<A[Dq.front()] && i>=k)
            { 
            maxim=A[Dq.front()];
            sol1=i;
            }                  
    }
  cout<<sol1-k+1<<" "<<sol1<<" "<<maxim;
 return 0;
}