Cod sursa(job #2291977)

Utilizator AlexPascu007Pascu Ionut Alexandru AlexPascu007 Data 28 noiembrie 2018 20:45:33
Problema Secventa Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
using namespace std;
//ifstream fin("secventa.in");
//ofstream fout("secventa.out");
int n,k,p,u,i,v[500010],d[500010],st,dr,sol;
int main() {
	freopen("secventa.in","r",stdin);
	freopen("secventa.out","w",stdout);
    scanf("%d%d",&n,&k); sol=-2000000;
    for (i=1;i<=n;i++)
        scanf("%d",&v[i]);
    p=1; u=1; d[1]=1;
    for (i=2;i<=n;i++) {
        while (v[i]<v[d[u]]&&p<=u)
            u--;
        d[++u]=i;
        if (i-d[p]==k)
            p++;
        if (i>=k&&v[d[p]]>sol) {
			sol=v[d[p]];
			st=i-k+1;
			dr=i;
        }
    }
	printf("%d %d %d",st,dr,sol);
    return 0;
}