mohammedehab2002

Untitled

Jun 13th, 2020
4,537
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int p[100005];
  4. int main()
  5. {
  6.     int t;
  7.     scanf("%d",&t);
  8.     while (t--)
  9.     {
  10.         int n;
  11.         scanf("%d",&n);
  12.         for (int i=1;i<=n;i++)
  13.         scanf("%d",&p[i]);
  14.         vector<int> ans;
  15.         for (int i=1;i<=n;i++)
  16.         {
  17.             if (i==1 || i==n || (p[i-1]<p[i])!=(p[i]<p[i+1]))
  18.             ans.push_back(p[i]);
  19.         }
  20.         printf("%d\n",ans.size());
  21.         for (int i:ans)
  22.         printf("%d ",i);
  23.         printf("\n");
  24.     }
  25. }
RAW Paste Data