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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.