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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.