Pagini recente » Cod sursa (job #2951169) | Cod sursa (job #2789951) | Cod sursa (job #2590512) | Cod sursa (job #3227978) | Cod sursa (job #2911420)
#include <fstream>
using namespace std;
ifstream cin("secventa.in");
ofstream cout("secventa.out");
int n, k, a[500000], deq[500010], front, top, maxi = -0x3f3f3f3f, r;
int main()
{
cin.tie(0); cout.tie(0);
cin >> n >> k;
front = 0, top = 0;
deq[0] = 0;
cin >> a[0];
for(int i = 1; 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 - 1 && maxi < a[deq[front]])
{
maxi = a[deq[front]];
r = i;
}
}
cout << r - k + 2 << ' ' << r + 1 << ' ' << maxi << '\n';
return 0;
}