Advertisement
Dang_Quan_10_Tin

ROTATION

Jul 9th, 2022
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. constexpr int N = 4e5 + 5;
  7. constexpr ll Inf = 1e17;
  8.  
  9. int n, a[N];
  10.  
  11. void Read()
  12. {
  13.     cin >> n;
  14.  
  15.     for (int i = 1; i <= n * 2; ++i)
  16.         cin >> a[i];
  17. }
  18.  
  19. void Solve()
  20. {
  21.     if (n == 1)
  22.         cout << a[1];
  23.     else if (n == 2)
  24.         cout << max(max(a[1] + a[2], a[2] + a[4]), max(a[3] + a[4], a[3] + a[1]));
  25.     else
  26.     {
  27.         sort(a + 1, a + n * 2 + 1, greater<int>());
  28.         ll ans(0);
  29.  
  30.         for (int i = 1; i <= n; ++i)
  31.             ans += a[i];
  32.  
  33.         cout << ans;
  34.     }
  35. }
  36.  
  37. int32_t main()
  38. {
  39.     ios::sync_with_stdio(0);
  40.     cin.tie(0);
  41.     cout.tie(0);
  42.     Read();
  43.     Solve();
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement