Mahmoud_Hawara

Untitled

Jul 19th, 2022
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  4. const long long MOD = 1e9 + 7, OO = 1e18;
  5. const double PI = acos(-1);
  6. const int N = 1e6 + 5;
  7. const int dx[4] = {0, 0, 1, -1};
  8. const int dy[4] = {1, -1, 0, 0};
  9.  
  10. long long t, n, k, a[N];
  11.  
  12. int main()
  13. {
  14.     IO
  15.     // vector<long long>v;
  16.     // for (int i = 0; i < 5; i++)
  17.     // {
  18.     //     v.push_back(i);
  19.     // }
  20.     // for (auto &x : v)
  21.     // {
  22.     //     x++;
  23.     // }
  24.     // for (auto x : v)
  25.     // {
  26.     //     cout << x << ' ';
  27.     // }
  28.     // long long y = 1;
  29.     // long long &x = y;
  30.     // cout << x << ' ' << y << '\n';
  31.     // x++;
  32.     // cout << x << ' ' << y;
  33.     cin >> t;
  34.     while (t--)
  35.     {
  36.         deque<long long>dq;
  37.         long long mx = -OO;
  38.         cin >> n >> k;
  39.         for (int i = 1; i <= n; i++)
  40.         {
  41.             cin >> a[i];
  42.             if (i <= k)
  43.             {
  44.                 dq.push_back(a[i]);
  45.                 mx = max(mx, a[i]);
  46.             }
  47.         }
  48.         cout << mx << ' ';
  49.         for (int i = 2; i + k - 1 <= n; i++)
  50.         {
  51.             dq.pop_front();
  52.             dq.push_back(a[i + k - 1]);
  53.             mx = -OO;
  54.             for (auto x : dq)
  55.             {
  56.                 mx = max(mx, x);
  57.             }
  58.             cout << mx << ' ';
  59.         }
  60.         cout << '\n';
  61.     }
  62.     return 0;
  63.     // auto x = "mahmoud";
  64.     // cout << x;
  65. }
  66.  
  67. // vctor<char>v;
  68.  
  69. // x = v[0];
  70. // x = v[1];
  71. // x = v[2];
  72. // x = v[3];
  73. // x = v[4];
  74.  
  75. // for (auto x  : v)
  76. // {
  77.  
  78. // }
  79.  
  80. /*
  81.     1 2 -1 4 5
  82.     mx = -OO;
  83.     mx = max(-OO, 1) = 1;
  84.     mx = max(1, 2) = 2
  85.     mx = max(2, -1) = 2
  86. */
  87.  
Advertisement
Add Comment
Please, Sign In to add comment