Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <stdio.h>
- std::vector<int> A, B, C;
- void build(const std::vector<int> A, int k, int razmer){
- int n = razmer;
- B.resize(n);
- C.resize(n);
- B.front() = A.front();
- C.back() = A.back();
- k--;
- for(int i1(1), i2(n - 2); i1 < n; i1++, i2--){
- B[i1] = (i1 % k) ? std::max(A[i1], B[i1 - 1]) : A[i1];
- C[i2] = ((i2 + 1) % k) ? std::max(A[i2], C[i2 + 1]) : A[i2];
- }
- }
- int main(){
- int m, count;
- A.resize(100001);
- scanf("%d", &m);
- count = 0;
- while(true){
- scanf("%d", &A[count]);
- if(A[count] == -1) break;
- count++;
- }
- build(A, m, count);
- int l = 0;
- while(count - 1 >= m){
- printf("%d\n", std::max(C[l], B[l + m - 1]));
- l++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment