Pagini recente » Cod sursa (job #80071) | Cod sursa (job #1286560) | Cod sursa (job #2804014) | Cod sursa (job #2246141) | Cod sursa (job #3151545)
#include <iostream>
#include <fstream>
#include <deque>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int main()
{
deque<pair<int, int>> d;
int n, a, k, ind=0;
int maxim=-999999;
fin >> n >> k;
for (int i=1; i<=n; ++i) {
fin >> a;
// -1 2 3 1 0 4 8 6
while(!d.empty() && d.back().first>a) {
d.pop_back();
}
d.emplace_back(a,i);
if (!d.empty() && d.front().second==i-k) {
//cout << d.front().first << ' ' << d.front().second << '\n';
d.pop_front();
}
cout << i << ' ' << d.front().first << '\n';
if (!d.empty() && i>=k) {
if(maxim<d.front().first) {
maxim=d.front().first;
ind=i;
}
}
}
fout << ind-k+1<< ' ' << ind << ' ' << maxim;
return 0;
}