Pagini recente » Istoria paginii runda/autumn19/clasament | Cod sursa (job #1774552) | politia | Monitorul de evaluare | Cod sursa (job #778834)
Cod sursa(job #778834)
using namespace std;
#include<fstream>
#include<deque>
#include<set>
#include<algorithm>
#define pair pair<int,int>
#define mp make_pair
int main ()
{
int n,k,i=0,x,ok,inf,sup,min,rezmin=32000,rezsup,rezinf;
deque<pair> v;
set<int> heap;
ifstream f("secventa.in");
min=30001;
f>>n>>k;
for(i=1;i<=k;i++)
{
f>>x;
while(!v.empty() && x<v.back().first)
v.pop_back();
v.push_back(mp(x,i));
if(x<rezmin)
rezmin=x;
}
i=k;
while(i!=n)
{
i++,f>>x;
while(!v.empty() && x<v.back().first)
v.pop_back();
v.push_back(mp(x,i));
if(v.back().second-v.front().second==k)
v.pop_front();
if(v.front().first>rezmin)
rezmin=v.front().first,rezsup=v.back().second,rezinf=v.front().second;
}
f.close();
ofstream g("secventa.out");
g<<rezinf<<" "<<rezsup<<" "<<rezmin;
return 0;
}