Pagini recente » Cod sursa (job #1991475) | Cod sursa (job #604295) | Cod sursa (job #86945) | Cod sursa (job #1770191) | Cod sursa (job #3194964)
#include <fstream>
#include <deque>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int main(){
vector<int> v;
deque<int> dq;
int n, k, st, dr, mn;
fin >> n >> k;
for (int i = 1; i <= n; i++){
int x;
fin >> x;
v.push_back(x);
}
for (int i = 0; i < k; i++){
while (!dq.empty() && v[dq.back()] > v[i]){
dq.pop_back();
}
dq.push_back(i);
}
mn = v[dq.front()];
st = 1;
dr = k;
for (int i = k; i < v.size(); i++){
int temp_mn, temp_st = ((i + 1) - k + 1), temp_dr = (i + 1);
while (!dq.empty() && v[dq.back()] > v[i]){
dq.pop_back();
}
if (dq.front() == temp_st - 2)
dq.pop_front();
dq.push_back(i);
temp_mn = v[dq.front()];
if (mn < temp_mn){
mn = temp_mn;
st = temp_st;
dr = temp_dr;
}
}
fout << st << " " << dr << " " << mn;
return 0;
}