Pagini recente » Cod sursa (job #1696919) | Cod sursa (job #167871) | Cod sursa (job #889918) | Cod sursa (job #1735035) | Cod sursa (job #1052756)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
int main()
{
ifstream in("secventa.in", ios::in);
ofstream out("secventa.out", ios::out);
unsigned int n, k;
in >> n >> k;
vector<pair<int, unsigned int>> S(n);
unsigned int i = 0u;
for (auto& s : S) { in >> s.first; s.second = i++; }
auto op = greater<pair<int, unsigned int>>();
make_heap(begin(S), begin(S) + k, op);
auto end_heap = begin(S) + k;
auto ans = S.front();
for (auto i = end_heap; i < end(S); ++i) {
while (S.front().second +k <= i->second) pop_heap(begin(S), end_heap--, op);
*end_heap++ = *i;
push_heap(begin(S), end_heap, op);
if (ans.first < S.front().first) ans = S.front();
}
out << ans.second +1 << ' ' << ans.second + k << ' ' << ans.first << endl;
out.close();
return 0;
}