Codeforces Round #726 (Div.2) 1537C - Challenging Cliffs Solution



  Problem Link: https://codeforces.com/problemset/problem/1537/C

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int main() {
  10. int t;
  11. cin >> t;
  12. while (t--) {
  13. int n, i;
  14. cin >> n;
  15. int a[n + 1];
  16. for (i = 0; i < n; i++) cin >> a[i];
  17. sort(a, a + n);
  18. if (n == 2) {
  19. cout << a[0] << " " << a[1] << endl;
  20. continue;
  21. }
  22. int mn = INT_MAX, pos = -1;
  23. for (i = 1; i < n; i++) {
  24. if (mn > abs(a[i] - a[i - 1])) {
  25. pos = i;
  26. mn = abs(a[i] - a[i - 1]);
  27. }
  28. }
  29. for (int i = pos; i < n; i++) cout << a[i] << " ";
  30. for (int i = 0; i < pos; i++) cout << a[i] << " ";
  31. cout << endl;
  32. }
  33. }

No comments

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.