Pagini recente » Cod sursa (job #1902591) | Cod sursa (job #243683) | Cod sursa (job #2091646) | Cod sursa (job #1743725) | Cod sursa (job #2037999)
#include <bits/stdc++.h>
using namespace std;
deque <int>q;
int n, k, a[500015];
void Citire()
{
ifstream fin("secventa.in");
fin >> n >> k;
for(int i = 1; i <= n; i++)
fin >> a[i];
fin.close();
}
void Secventa()
{
int i, x, ind1, ind2, bazmax;
for(int i = 1; i <= k; i++)
{
int x = a[i];
while(!q.empty() && x <= a[q.front()])
q.pop_back();
q.push_back(i);
}
bazmax = a[q.front()];
ind1 = q.back() - k + 1;
ind2 = q.back();
for(i = k + 1; i <= n; i++)
{
x = a[i];
while(!q.empty() && x <= a[q.front()])
q.pop_back();
q.push_back(i);
if(q.front() <= i - k) q.pop_front();
if(a[q.front()] > bazmax)
{
bazmax = a[q.front()];
ind1 = q.back() - k + 1;
ind2 = q.back();
}
}
ofstream fout("secventa.out");
fout << ind1 << " " << ind2 << " " << bazmax << "\n";
fout.close();
}
int main()
{
Citire();
Secventa();
return 0;
}