Pagini recente » Cod sursa (job #2060012) | Cod sursa (job #2069181) | Cod sursa (job #2840947) | Cod sursa (job #1558598) | Cod sursa (job #2037480)
#include <fstream>
#include <deque>
#define Nmax 500010
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
int n,k,j,vmax=-300001,u,A[Nmax];
deque < pair <int, int> > D;
char s[10000005];
int main()
{ f>>n>>k; f.get();
f.getline(s, 10000005);
for(int i=1;i<=n;i++)
{ int sign=1;
if(s[j]==' ') j++;
if(s[j]=='-') {sign=-1; j++;}
while('0'<=s[j] and s[j]<='9') {A[i]=A[i]*10+s[j]-'0'; j++;}
A[i]*=sign;
}
for(int i=1;i<=n;i++)
{ while(!D.empty() and A[i]< D.back().first) D.pop_back();
D.push_back(make_pair(A[i], i));
if(D.front().second<=i-k) D.pop_front();
if(i>=k and D.front().first>vmax) {vmax=D.front().first; u=i;}
}
g<<u-k+1<<' '<<u<<' '<<vmax<<'\n'; g.close(); return 0;
}