Cod sursa(job #2758014)

Utilizator lahayonTester lahayon Data 7 iunie 2021 23:33:13
Problema Secventa Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#include <deque>

using namespace std;


int main(){    

    ifstream cin("secventa.in");
    ofstream cout("secventa.out");

    int N, K, current, max_base = -1 << 15;
    pair<int, int> pos;
   
    cin >> N >> K;
    deque<pair<int, int>> DEQ;
    for(int i = 1; i <= N; ++i){

        cin >> current;
        while(!DEQ.empty() && current <= DEQ.back().first)
            DEQ.pop_back();
        while(!DEQ.empty() && DEQ.front().second <= i - K)
            DEQ.pop_front();
        DEQ.push_back(pair<int, int>(current, i));
        if(i >= K && DEQ.front().first > max_base){
                max_base = DEQ.front().first;
                pos = make_pair(i - K + 1, i);
              
            }
    }

    cout << pos.first << " " << pos.second << " " << max_base;

    cin.close();
    cout.close();

  return 0;
	
}