Pagini recente » Cod sursa (job #1679025) | Sandbox (cutiuţa cu năsip) | Clasament winners7 | Cod sursa (job #1066038) | Cod sursa (job #2839906)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
const int N = 5e5 + 7;
int n, i, k, mx = -3e4 - 7, l, r;
int v[N];
deque <int> deq;
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;
}
};
int main()
{
InParser fin("secventa.in");
std::ofstream fout("secventa.out");
fin >> n >> k;
for(i = 1; i <= n; i++){
fin >> v[i];
}
for(i = 1; i <= n; i++){
while(!deq.empty() && v[i] <= v[deq.back()]){
deq.pop_back();
}
deq.push_back(i);
if(deq.front() == i - k){
deq.pop_front();
}
if(i >= k && mx < v[deq.front()]){
mx = v[deq.front()];
l = i - k + 1;
r = i;
}
}
fout << l << " " << r << " " << mx;
return 0;
}