Cod sursa(job #2077680)

Utilizator RaduGiucleaGiuclea Radu RaduGiuclea Data 28 noiembrie 2017 14:20:25
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <cstdio>
#include <deque>
using namespace std;
struct aa{int poz;int v;};
deque <aa> d;
int main()
{
    freopen("secventa.in","r",stdin);
    freopen("secventa.out","w",stdout);
    int n,i,mx=-31000,st,fin,k;
    aa x;
    scanf("%d%d",&n,&k);
    for(i=1;i<=k-1;i++)
    {
        scanf("%d",&x.v);
        x.poz=i;
        while(!d.empty()&&d.back().v>=x.v)
            d.pop_back();
        d.push_back(x);
    }
    for(i=k;i<=n;i++)
    {
        if(d.front().poz==i-k)
            d.pop_front();
        scanf("%d",&x.v);
        x.poz=i;
        while(!d.empty()&&d.back().v>=x.v)
            d.pop_back();
        d.push_back(x);
        if(d.front().v>mx)
            mx=d.front().v,st=i-k+1,fin=i;
    }
    printf("%d %d %d",st,fin,mx);
    return 0;
}