Pagini recente » Cod sursa (job #1405358) | Cod sursa (job #2440466) | Cod sursa (job #2247004) | Cod sursa (job #84687) | Cod sursa (job #983163)
Cod sursa(job #983163)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
#define MAX 500002
int k, n, v[MAX], xbase = -1000000, xmin, xmax;
deque<int> dq;
void print(){
cout << endl;
cout << n << " " << k << endl;
for(int i = 0; i < n; i ++){
cout << v[i] << " ";
}
cout << endl;
cout << xmin << " " << xmax << " " << xbase << endl;
cout << endl;
}
void read(){
ifstream fi("secventa.in");
fi >> n;
fi >> k;
for (int i = 1; i <= n; i ++){
fi >> v[i];
}
fi.close();
}
void write(){
ofstream fo("secventa.out");
fo << xmin << " " << xmax << " " << xbase;
fo.close();
}
void compute(){
for(int i = 1; i <= n; i ++){
while(!dq.empty() && dq.front() < i - k + 1){
dq.pop_front();
}
while(!dq.empty() && v[i] < v[dq.back()]){
dq.pop_back();
}
dq.push_back(i);
if(i > k - 1 && v[dq.front()] > xbase){
xbase = v[dq.front()];
xmin = i - k + 1;
xmax = i;
}
}
print();
}
int main(void){
read();
compute();
write();
return 0;
}