Pagini recente » Cod sursa (job #1920045) | Cod sursa (job #530089) | Cod sursa (job #1795533) | Cod sursa (job #1590317) | Cod sursa (job #358636)
Cod sursa(job #358636)
#include <iostream>
#include <fstream>
#include <deque>
#include <algorithm>
using namespace std;
int main() {
deque<pair <int, int> > deq;
fstream f1, f2;
f1.open("secventa.in", ios::in);
int n, k, mat, i, max, min, start;
f1>>n>>k>>mat;
deq.push_back(make_pair(mat, 1));
for(i=2; i<=k; i++) {
f1>>mat;
while(!deq.empty() && mat<=deq.back().first) {
deq.pop_back();
}
deq.push_back(make_pair(mat, i));
}
start=1; max=deq.front().first;
for(i=k+1; i<=n; i++) {
f1>>mat;
/**
while(!deq.empty() && deq.front().second<=i-k) {
deq.pop_front();
}
**/
if(deq.front().second<=i-k) { deq.pop_front(); }
while(!deq.empty() && mat<=deq.back().first) {
deq.pop_back();
}
deq.push_back(make_pair(mat, i));
if(deq.front().first>max) { max=deq.front().first; start=deq.front().second; }
}
f2<<start<<" "<<start+k-1<<" "<<max;
f1.close(); f2.close();
return 0;
}