|
0
Woowww no TLE involved??? :333 |
|
-17
Sort the array find out all the element whose indexes &1 and !&1. Seperate them all and put them with the following order: (!&1 indexes element (increase order)) (&1 indexes element (decrease order)). Thus, we have the following code in C++: include <bits/stdc++.h>using namespace std; typedef long long ll; define vi vectorvi last; ll n; main(){ cin >> n; ll a[n+1]; for(ll i=0; i<n; i++) cin >> a[i]; sort(a,a+n); ll ans[n+1]; ll j = 0, z = n — 1; for(ll i=0; i<n; i++){ if(i&1) ans[z--] = a[i]; else ans[j++] = a[i]; } for(ll i = 0; i < n; i++) cout<<ans[i] << " "; } /* CODE BY MyNameIsHung */ |