Pagini recente » Cod sursa (job #675258) | Cod sursa (job #1098816) | Cod sursa (job #2717221) | Cod sursa (job #142185) | Cod sursa (job #346365)
Cod sursa(job #346365)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define N_MAX 500001
int main() {
long n, k, x, i, q[N_MAX], pq = 0, uq = 0, max = -60000, pmax = -1;
long v[N_MAX];
ifstream fin;
ofstream fout;
fin.open("secventa.in");
fout.open("secventa.out");
fin >> n >> k;
for (i = 0; i < n; i++) {
fin >> x;
v[i] = x;
for (; uq != pq && q[uq - 1] > x; uq--);
q[uq++] = x;
if (i == k-1) max = q[pq], pmax = i;
if (i >= k) {
if (v[i - k] == q[pq]) pq++;
if (q[pq] > max) max = q[pq], pmax = i;
}
}
fout << pmax - k + 2 << " " << pmax + 1 << " " << max <<"\n";
fin.close();
fout.close();
return 0;
}