Advertisement
leminhkt

noname39 (solo)

Apr 5th, 2020
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define lFOR(i, a, b) for(ll i=(a); i<=(b); i++)
  5. #define lFORn(i, n) for(ll i=1; i<=(n); i++)
  6. #define lFORx(i, a, b, n) for(ll i=(a); i<=(b); i+=(x))
  7. #define FORa(i, b) for(i; i<=(b); i++)
  8. #define FORax(i, b, x) for(i; i<=(b); i+=(x))
  9. #define lFORR(i, a, b) for(ll i=(a); i>=(b); i--)
  10. #define lFORRn(i, n) for(ll i=(n); i>=1; i--)
  11. #define lFORRx(i, a, b, n) for(ll i=(a); i>=(b); i-=(x))
  12. #define FORRa(i, b) for(i; i>=(b); i--)
  13. #define FORRax(i, b, x) for(i; i>=(b); i-=(x))
  14. #define iFOR(i, a, b) for(int i=(a); i<=(b); i++)
  15. #define iFORn(i, n) for(int i=1; i<=(n); i++)
  16. #define iFORx(i, a, b, n) for(int i=(a); i<=(b); i+=(x))
  17. #define iFORR(i, a, b) for(int i=(a); i>=(b); i--)
  18. #define iFORRn(i, n) for(int i=(n); i>=1; i--)
  19. #define iFORRx(i, a, b, n) for(int i=(a); i>=(b); i-=(x))
  20. #define pb(x) push_back(x)
  21. #define all(x) (x).begin(), (x).end()
  22. #define sz(x) (x).size()
  23. #define sqr(x) (ll)(x)*(x)
  24. #define PI (2*acos(0))
  25. using namespace std;
  26.  
  27. template <typename T>
  28. inline void Read(T& x)
  29. {
  30.     bool Neg = false;
  31.     char c;
  32.     for (c = getchar(); c < '0' || c > '9'; c = getchar())
  33.         if (c == '-') Neg = !Neg;
  34.     x = c - '0';
  35.     for (c = getchar(); c >= '0' && c <= '9'; c = getchar())
  36.         x = x * 10 + c - '0';
  37.     if (Neg) x = -x;
  38. }
  39. template <typename T>
  40. inline void Write(T x)
  41. {
  42.     if (x < 0)
  43.     {
  44.         putchar('-'); x = -x;
  45.     }
  46.     T p = 1;
  47.     for (T temp = x / 10; temp > 0; temp /= 10) p *= 10;
  48.     for (; p > 0; x %= p, p /= 10) putchar(x / p + '0');
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.         //=================declare=================
  57.     int t, n, k, p, res, inp;
  58.     vector<int> a(102);
  59.  
  60.  
  61.  
  62.  
  63. //=================..end..=================
  64.         //=================function=================
  65.  
  66.  
  67.  
  68.  
  69.  
  70. //=================..end...=================
  71. int main(){
  72.     freopen("solo.inp", "r", stdin);
  73.     freopen("solo.out", "w", stdout);
  74.     // ios_base::sync_with_stdio(0); cin.tie(0);
  75.         //=================code=================
  76.     Read(t);
  77.     while(t--){
  78.         Read(n);
  79.         Read(k);
  80.         Read(p);
  81.         if(k&1){
  82.             if(p==0){
  83.                 res=0;
  84.                 while(n--){
  85.                     cin>>inp;
  86.                     res=max(res, inp);
  87.                 }
  88.             }
  89.             else{
  90.                 res=1000000001;
  91.                 while(n--){
  92.                     cin>>inp;
  93.                     res=min(res, inp);
  94.                 }
  95.             }
  96.         }
  97.         else{
  98.             if(p==0){
  99.                 res=0;
  100.                 a[0]=a[n+1]=1000000001;
  101.                 iFORn(i, n){
  102.                     cin>>a[i];
  103.                     res=max(res, min(a[i-1], a[i+1]));
  104.                 }
  105.             }
  106.             else{
  107.                 res=1000000001;
  108.                 a[0]=a[n+1]=0;
  109.                 iFORn(i, n){
  110.                     cin>>a[i];
  111.                     res=min(res, max(a[i-1], a[i+1]));
  112.                 }
  113.             }
  114.         }
  115.         Write(res);
  116.         cout<<'\n';
  117.     }
  118.  
  119.  
  120.  
  121.  
  122. //=================end.=================
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement