Pagini recente » Cod sursa (job #1346256) | Cod sursa (job #1153264) | Cod sursa (job #2140831) | Cod sursa (job #2171053) | Cod sursa (job #2758014)
#include <fstream>
#include <deque>
using namespace std;
int main(){
ifstream cin("secventa.in");
ofstream cout("secventa.out");
int N, K, current, max_base = -1 << 15;
pair<int, int> pos;
cin >> N >> K;
deque<pair<int, int>> DEQ;
for(int i = 1; i <= N; ++i){
cin >> current;
while(!DEQ.empty() && current <= DEQ.back().first)
DEQ.pop_back();
while(!DEQ.empty() && DEQ.front().second <= i - K)
DEQ.pop_front();
DEQ.push_back(pair<int, int>(current, i));
if(i >= K && DEQ.front().first > max_base){
max_base = DEQ.front().first;
pos = make_pair(i - K + 1, i);
}
}
cout << pos.first << " " << pos.second << " " << max_base;
cin.close();
cout.close();
return 0;
}