Codeforces Round #726 (Div.2) 1537C - Challenging Cliffs Solution
Problem Link: https://codeforces.com/problemset/problem/1537/C
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int t;
- cin >> t;
- while (t--) {
- int n, i;
- cin >> n;
- int a[n + 1];
- for (i = 0; i < n; i++) cin >> a[i];
- sort(a, a + n);
- if (n == 2) {
- cout << a[0] << " " << a[1] << endl;
- continue;
- }
- int mn = INT_MAX, pos = -1;
- for (i = 1; i < n; i++) {
- if (mn > abs(a[i] - a[i - 1])) {
- pos = i;
- mn = abs(a[i] - a[i - 1]);
- }
- }
- for (int i = pos; i < n; i++) cout << a[i] << " ";
- for (int i = 0; i < pos; i++) cout << a[i] << " ";
- cout << endl;
- }
- }
No comments