Pagini recente » Istoria paginii utilizator/sbordeianu | Istoria paginii utilizator/mary136 | Monitorul de evaluare | Istoria paginii utilizator/karla10 | Cod sursa (job #2193208)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 500005;
int n, k, v[nmax], sol = -30005, soli;
deque<int> q;
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;
}
};
int main()
{
InParser fin ("secventa.in");
ofstream fout ("secventa.out");
fin >> n >> k;
for (int i = 1; i <= n; ++i)
fin >> v[i];
for (int i = 1; i <= n; ++i){
if(!q.empty() && i-q.front() == k)
q.pop_front();
while(!q.empty() && v[q.back()] >= v[i])
q.pop_back();
q.push_back(i);
if(v[q.front()] > sol && i >= k){
sol = v[q.front()];
soli = i-k+1;
}
}
fout << soli << " " << soli+k-1 << " " << sol << "\n";
return 0;
}