Pagini recente » Cod sursa (job #1439329) | Cod sursa (job #396068) | Cod sursa (job #49768) | Cod sursa (job #2573625) | Cod sursa (job #2676351)
#include <fstream>
#include <deque>
#include <stack>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
ifstream cin("secventa.in");
ofstream cout("secventa.out");
deque < int > dq;
stack < int > st;
const int NMAX=500005;
int v[NMAX], st1[NMAX], dr[NMAX];
int main()
{
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(false);
int n, i, j, k, maxx=-300005, poz = 0 ,poz1;
cin >> n >> k;
for( i=1; i<=n; i++ )
{
cin >> v[i];
while( !dq.empty() and v[dq.back()] > v[i] )
dq.pop_back();
dq.push_back( i );
if( dq.front() <= i - k )
dq.pop_front();
if( i>=k )
if( v[dq.front()] > maxx )
{
maxx = v[dq.front()];
poz = dq.front();
}
}
for ( i=1; i<=n; i++)
{
int h = i;
while( !st.empty() and v[st.top()] > v[i] )
{
h = st1[st.top()];
st.pop();
}
if( st.empty() )
{
st.push( i );
st1[i] = h;
}
else
{
st1[i] = h;
st.push( i );
}
if( i == poz )
break;
}
if( poz - st1[poz] >= k )
cout << st1[poz] << " " << poz << " " << maxx;
else
cout << st1[poz] << " " << st1[poz] + k -1 << " " << maxx;
return 0;
}