Pagini recente » Cod sursa (job #1374524) | Cod sursa (job #44652) | Cod sursa (job #2999570) | Cod sursa (job #298269) | Cod sursa (job #2269875)
#include <fstream>
#include <deque>
#include <algorithm>
#include <climits>
#include <cstring>
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
long long n, k, poz1=-1, poz2=-1, maxim=INT_MIN, a[5000001], j=1;
char s[50000001];
deque <long long> q;
int main()
{
f>>n>>k;
f.get();
f.getline(s, 50000001);
long lung=strlen(s);
for(int i=0; i<lung; i++)
{
int nr=0;
if(s[i]=='-')
{
i++;
while(s[i]>='0' && s[i]<='9')
{
nr=nr*10-(s[i]-'0');
i++;
}
a[j++]=nr;
}
else
{
while(s[i]>='0' && s[i]<='9')
{
nr=nr*10+(s[i]-'0');
i++;
}
a[j++]=nr;
}
}
for(int i=1; i<=n; i++)
{
while(!q.empty() && a[i]<=a[q.back()])
q.pop_back();
q.push_back(i);
if(i-q.front()==k)
q.pop_front();
if(i>=k && a[q.front()]>maxim)
{
maxim=a[q.front()];
poz1=i-k+1;
poz2=i;
}
}
g<<poz1<<" "<<poz2<<" "<<maxim;
return 0;
}