Cod sursa(job #542368)

Utilizator Rares95Rares Arnautu Rares95 Data 26 februarie 2011 12:34:46
Problema Secventa Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
# include <fstream>
  using namespace std;
  ifstream f("secventa.in"); ofstream g("secventa.out");
		int k, n, i, front = 1, back, deque[500001], a[500001], baza = -30001, p, u;
		int main ()
		{ f >> n >> k; for (i = 1; i <= n; ++i) f >> a[i];
			for (i = 1; i <= n; ++i)
			{ while (front <= back && a[i] <= a [ deque [ back ]]) back --;
			  deque [ ++ back ] = i;
			  if (deque [ front ] == i - k) front ++;
				if (i >= k && a [ deque [ front ]] > baza) {baza = a [ deque [ front ]]; p = (u = i) - k + 1;}
			}
			g << p << ' ' << u << ' ' << baza << '\n'; return 0;
		}