Pagini recente » Cod sursa (job #1093497) | Cod sursa (job #2890851) | Cod sursa (job #738867) | Clasament runda_de_test | Cod sursa (job #778533)
Cod sursa(job #778533)
using namespace std;
#include<fstream>
#include<deque>
#include<algorithm>
#define inF "secventa.in"
#define outF "secventa.out"
#define INF 32000
int main ()
{
int n,k,i=0,x,min=INF,inf ,sup;
deque<int>v;
pair<int,pair<int,int> > rez1;
rez1.first=INF;
ifstream f(inF);
f>>n>>k;
rez1.second.first=inf=1;
rez1.second.second=sup=k;
for(i=1;i<=k;i++)
{
f>>x;
if(x<min)
min=x;
if(v.size()>1)
while(x<=v.back() && v.size()>1)
v.pop_back();
v.push_back(x);
}
i=k;
rez1.first=min;
int nr_ap_min=k,copy_top;
copy_top=v.front();
while(i<=n)
{
f>>x;
while(x<=v.back() && v.size()>1)
v.pop_back();
if(nr_ap_min==k)
{
v.pop_front();
nr_ap_min=1;
}
v.push_back(x);
copy_top=v.front();
if(copy_top==v.front())
nr_ap_min++;
min=*min_element(v.begin(),v.end());
i++;
inf++;
sup++;
if(min>rez1.first)
{
rez1.first=min;
rez1.second.first=inf;
rez1.second.second=sup;
}
}
f.close();
ofstream g(outF);
g<<rez1.second.first<<" "<<rez1.second.second<<" "<<rez1.first;
g.close();
return 0;
}