Pagini recente » Cod sursa (job #2029482) | Cod sursa (job #1745814) | Cod sursa (job #2223414) | Cod sursa (job #1603323) | Cod sursa (job #1172227)
#include <fstream>
#include <deque>
using namespace std;
ifstream is ("secventa.in");
ofstream os ("secventa.out");
deque <int> D;
int n, k, a[500001], x, maxim = -30001;
int main()
{
is >> n >> k;
for(int i = 1; i <= n; ++i)
{
is >> a[i];
while(!D.empty() && a[i] <= a[D.back()])
D.pop_back();
D.push_back(i);
if(D.front() == i-k)
D.pop_front();
if(i >= k)
if(a[D.front()] > maxim )
{
maxim = a[D.front()];
x = D.front();
}
}
if(x+k-1 <= n)
os << x-k+1 << ' ' << x<< ' ' << maxim;
is.close();
os.close();
return 0;
}