Pagini recente » Cod sursa (job #2561917) | Cod sursa (job #1034517) | Cod sursa (job #2630184) | Cod sursa (job #1725628) | Cod sursa (job #2433459)
#include <bits/stdc++.h>
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
deque <pair<int,int>> coada;
int main()
{ int n,k;
f>>n>>k;
int dr,eMax=-30005;
for(int x,i=1; i<=n; i++)
{ f>>x;
bool ok=true;
while(!coada.empty() && ok)
{ int ul=coada.back().first;
ok=false;
if(x<=ul)
{ ok=true;
coada.pop_back();
}
}
coada.push_back({x,i});
if(coada.front().second==i-k) coada.pop_front();
if(i>=k && coada.front().first>eMax)
{ eMax=coada.front().first;
dr=i;
}
}
g<<dr-k+1<<' '<<dr<<' '<<eMax;
return 0;
}