Cod sursa(job #2053054)

Utilizator ioana_99Ioana Marin ioana_99 Data 31 octombrie 2017 13:30:18
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("secventa.in");
ofstream g("secventa.out");
const int N=500010;
int v[N],n,k,st,dr,d[N],j,i,stg_min,drpt_min,baza_max;

struct vect
{
 int drpt,stg,val;
}poz[N];

int main()
{
 f>>n>>k;
 for(i=1; i<=n; i++)
 {
     f>>v[i];
 }
 baza_max=-30002;
 st=0;
 dr=-1;
 for(i=1; i<=n; i++)
 {
     if(st<=dr && i>=k && v[i]<=v[d[dr]])
     {
         st++;
     }
     while(st<=dr && v[i]<=v[d[dr]])
     {
         dr--;
     }
     d[++dr]=i;
     if(i>=k)
     {
         if(v[d[st]]>=baza_max)
         {
        j++;
        poz[j].drpt=d[dr];
        poz[j].stg=d[st];
        poz[j].val=v[d[st]];
        baza_max=v[d[st]];
         }

     }
 }
 i=j-1;
 stg_min=poz[j].stg;
 drpt_min=poz[j].drpt;
 while(baza_max==poz[i].val)
 {
    stg_min=min(stg_min,poz[i].stg);
 }
 i=j-1;
 while(baza_max==poz[i].val)
 {
     if(poz[i].stg==stg_min)
        drpt_min=min(drpt_min,poz[i].drpt);
 }
 g<<stg_min<<" "<<drpt_min<<" "<<baza_max;
    return 0;
}