Pagini recente » Cod sursa (job #745015) | Cod sursa (job #68991) | Cod sursa (job #1404054) | Cod sursa (job #51121) | Cod sursa (job #2911418)
#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(front <= top && deq[front] <= i - k)
front++;
while(front <= top && a[deq[top]] >= a[i])
top--;
top++;
deq[top] = i;
if(i > k && maxi < a[deq[front]])
{
maxi = a[deq[front]];
r = i;
}
}
cout << r - k + 2 << ' ' << r + 1 << ' ' << maxi << '\n';
return 0;
}