Cod sursa(job #2460889)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 24 septembrie 2019 17:30:15
Problema Secventa Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <iostream>
#include <fstream>
#include <deque>

using namespace std;

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

#define ll long long
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 500000;
int v[1 + nmax];
deque<int> dq;

int main()
{
  int n, k;
  in >> n >> k;
  for(int i = 1;i <= n; i++)
    in >> v[i];

  int smax = -nmax, x = 0, y = 0;

  for(int i = 1;i <= n; i++){
    while(0 < dq.size() && v[i] < v[dq.back()])
      dq.pop_back();
    dq.push_back(i);
    while(0 < dq.size() && dq.front() <= i - k)
      dq.pop_front();

    if(smax < v[dq.front()]){
      smax = v[dq.front()];
      x = i - k + 1;
      y = i;
    }
  }

  out << x << " " << y << " " << smax;
  return 0;
}