Codeforces 1339B. Sorted Adjacent Differences Solution

Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
#include <algorithm>
#define ef(i,a,b) for(int i=a; i<=b; i++)
#define enf(i,b,a) for(int i=b; i>=a; i--)
using namespace std;
const int M = 100000 + 9;
int main()
{
    int t,ar[M],n,i,j;
    while(cin>>t)
    {
        while(t--)
        {
            cin>>n;
            ef(i,1,n)
            cin>>ar[i];
            sort(ar+1,ar+1+n);
            if(n%2==1)
            cout<<ar[(n+1)/2]<<" ";
            enf(i,n/2,1)
            cout<<ar[n-i+1]<<" "<<ar[i]<<" ";
            cout<<endl;
        }
    }
}

2 comments:

  1. can you please explain statement cin>>t??

    ReplyDelete
    Replies
    1. cin>>t it use for get input from keyboard.here is 't' is test case number

      Delete

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.