Cod sursa(job #1469698)

Utilizator FairPlay94George Cioroiu FairPlay94 Data 9 august 2015 12:24:47
Problema Secventa Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <climits>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <map>
#include <algorithm>
#include <string>
#include <deque>

using namespace std;

void afis(deque<int> d) {
    for (int i = 0; i < d.size(); i++)
        cout << d[i] << " ";
    cout << "\n\n";
}

int main() {
    freopen("secventa.in", "r", stdin);
    freopen("secventa.out", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    int v[500005];
    for (int i = 1; i <= n; i++)
        cin >> v[i];
    deque<int> d;
    int ans = -30005, e;
    for (int i = 1; i < k; i++) {
        while (!d.empty() && v[i] < d.back())
            d.pop_back();
        d.push_back(i);
    }
    for (int i = k; i <= n; i++) {
        while (!d.empty() && v[i] < v[d.back()])
            d.pop_back();
        d.push_back(i);
        if (d.front() == i - k)
            d.pop_front();
        if (v[d.front()] > ans) {
            ans = v[d.front()];
            e = i;
        }
    }
    cout << e - k + 1 << " " << e << " " << ans;

    return 0;
}