Pagini recente » Cod sursa (job #2485962) | Cod sursa (job #1543554) | Cod sursa (job #585111) | Cod sursa (job #614278) | Cod sursa (job #2911421)
#include <fstream>
using namespace std;
ifstream cin("secventa.in");
ofstream cout("secventa.out");
int n, k, a[500001], deq[500010], front, top, maxi = -0x3f3f3f3f, r;
int main()
{
cin >> n >> k;
front = 1, top = 1;
deq[1] = 1;
cin >> a[1];
for(int i = 2; i <= n; i++)
{
cin >> a[i];
while(k <= i - deq[front] && front <= top)
front++;
while(a[deq[top]] >= a[i] && front <= top)
top--;
top++;
deq[top] = i;
if(i >= k && maxi < a[deq[front]])
{
maxi = a[deq[front]];
r = i;
}
}
cout << r - k + 1 << ' ' << r << ' ' << maxi << '\n';
return 0;
}