Cod sursa(job #1930459)

Utilizator waren4Marius Radu waren4 Data 18 martie 2017 22:04:40
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

ifstream f("secventa.in"); ofstream g("secventa.out");
int n,k,a[500001],d[500001],i,m,st,dr,x,y;
string s;
long long j;
int main()
{
    f>>n>>k;
    for(i = 1; i <= n; ++i) {
        f>>a[i];
    }
   /* f>>s;
    j = s.length();
    i = 0;
    x = 0;
    y = 0;
    cout<<s;
    while( x <= j) {
        if (s[x] >= '0' && s[x] <= '9') {
            ++y;
            a[y] = 0;
            while (s[x] >= '0' && s[x] <= '9') {
                a[y] = a[y] * 10 + (s[x] - '0');
                ++x;
            }
        }
        if (s[x] == ' ') {
            ++x;
        }
    }*/
    dr = 0;
    st = 1;
    m = -1000000;
    for(i = 1; i <= n; ++i) {
        while( st <= dr && a[i] < a[d[dr]]) {
            --dr;
        }
        ++dr;
        d[dr] = i;
        if (d[st] == i - k) {
            ++st;
        }
        if (i >= k && a[d[st]] > m) {
            m = a[d[st]];
            x = i-k+1;
            y = i;
        }
    }
    g<<x<<' '<<y<<' '<<m;
    return 0;
}