Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- constexpr int N = 4e5 + 5;
- constexpr ll Inf = 1e17;
- int n, a[N];
- void Read()
- {
- cin >> n;
- for (int i = 1; i <= n * 2; ++i)
- cin >> a[i];
- }
- void Solve()
- {
- if (n == 1)
- cout << a[1];
- else if (n == 2)
- cout << max(max(a[1] + a[2], a[2] + a[4]), max(a[3] + a[4], a[3] + a[1]));
- else
- {
- sort(a + 1, a + n * 2 + 1, greater<int>());
- ll ans(0);
- for (int i = 1; i <= n; ++i)
- ans += a[i];
- cout << ans;
- }
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement