T3000

Untitled

Feb 5th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. int main()
  7. {
  8.     ll t;
  9.     cin >> t;
  10.     ll x;
  11.     deque<ll> z1;
  12.     while (t-- > 0)
  13.     {
  14.         cin >> x;
  15.         ll sum = 0;
  16.         ll a, nbn = 20;
  17.         while (nbn-- > 0)
  18.         {
  19.             cin >> a;
  20.             z1.push_back(a);
  21.         }
  22.  
  23.         while (true)
  24.         {
  25.             ll val = 1;
  26.             for (int i = 0; i < 19; i++)
  27.             {
  28.                 if (z1.at(i) > z1.at(i + 1))
  29.                 {
  30.                     swap(z1.at(i), z1.at(i++));
  31.                     val = 0;
  32.                     sum += 1;
  33.                 }
  34.             }
  35.  
  36.             if (val == 1)
  37.             {
  38.                 break;
  39.             }
  40.         }
  41.         cout << x << " " << sum << '\n';
  42.         z1.clear();
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment