Pagini recente » Cod sursa (job #2841874) | Istoria paginii utilizator/petreionut69420 | Cod sursa (job #1700895) | Cod sursa (job #2846953) | Cod sursa (job #2269931)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
deque <pair <short, int > > deck;
int main()
{
int n, k, x, rez;
f >> n >> k;
short maxi = -30005;
for(int i = 1; i <= n; i++)
{
f >> x;
if(i-deck.front().second+1 > k)
deck.pop_front();
while(!deck.empty() && deck.back().first > x)
deck.pop_back();
deck.push_back({x, i});
if(i >= k)
if(maxi < deck.front().first)
{
maxi = deck.front().first;
rez = deck.back().second;
}
}
g << rez-k+1 << ' ' << rez << ' ' << maxi;
return 0;
}