Pagini recente » Cod sursa (job #283401) | Cod sursa (job #2281434) | Cod sursa (job #1492209) | Cod sursa (job #2510642) | Cod sursa (job #1441212)
#include <deque>
#include <fstream>
using namespace std;
const int dmax = 500003;
deque < int > D;
int a[dmax];
int main(){
ifstream fin ("secventa.in");
ofstream fout ("secventa.out");
int N, K, start, end, worst = -dmax;
fin >> N >> K;
for (int i = 1; i <= N; i++)
fin >> a[i];
for (int i = 1; i <= N; i++){
while ( !D.empty() && a[i] <= a[D.back()]) D.pop_back();
D.push_back(i);
if (D.front() == i - K ) D.pop_front();
if (i >= K){
if (a[D.front()] > worst) worst = a[D.front()], start = i - K + 1 , end = i;;
}
}
fout << start << " " << end << " " << worst;
return 0;
}