Pagini recente » Cod sursa (job #366845) | Cod sursa (job #2243445) | Cod sursa (job #277546) | Cod sursa (job #1800564) | Cod sursa (job #778838)
Cod sursa(job #778838)
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,rezmin=32000,rezsup,rezinf;
deque<pair> v;
set<int> heap;
ifstream f("secventa.in");
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;
}
}
if(k==n)
{
rezinf=1;
rezsup=k;
}
else
rezinf=v.front().second,rezsup=v.back().second;
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;
}