Pagini recente » Cod sursa (job #2767118) | Cod sursa (job #17292) | Cod sursa (job #1902349) | Cod sursa (job #986547) | Cod sursa (job #2460893)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
} in ("secventa.in");
ofstream out ("secventa.out");
#define ll long long
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 500000;
int v[1 + nmax];
deque<int> dq;
int main()
{
int n, k;
in >> n >> k;
for(int i = 1;i <= n; i++)
in >> v[i];
int smax = -nmax, x = 0, y = 0;
for(int i = 1;i <= n; i++){
while(0 < dq.size() && v[i] <= v[dq.back()])
dq.pop_back();
dq.push_back(i);
while(0 < dq.size() && dq.front() <= i - k)
dq.pop_front();
if(k <= i && smax < v[dq.front()]){
smax = v[dq.front()];
x = i - k + 1;
y = i;
}
}
out << x << " " << y << " " << smax;
return 0;
}