Pagini recente » Atasamentele paginii Clasament ffcxzczxczx | Cod sursa (job #2885409) | Cod sursa (job #2547852) | lista-de-probleme | Cod sursa (job #2462964)
#include <fstream>
#include <deque>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int n, k, currentNr;
deque<pair<int, int>> deq;
int bazaMaxi;
int pSf;
int main()
{
fin >> n >> k;
bazaMaxi = -2147483648;
for (int i = 0; i < n; ++i) {
fin >> currentNr;
while (!deq.empty() && currentNr <= deq.back().first) {
deq.pop_back();
}
deq.push_back(make_pair(currentNr, i));
if (i - deq.front().second == k) {
deq.pop_front();
}
if (i >= k - 1 && deq.front().first > bazaMaxi)
{
bazaMaxi = deq.front().first;
pSf = i;
}
}
fout << pSf - k + 2 << " " << pSf + 1 << " " << bazaMaxi << "\n";
return 0;
}