Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<algorithm>
- #include<deque>
- #define long long long
- #define nln '\n'
- using namespace std;
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("book.inp", "r", stdin);
- long n;
- cin >> n;
- deque<long> a(n);
- for (auto &i :a)
- cin >> i;
- sort(a.begin(), a.end());
- long ans = 0;
- if (n % 3 != 0)
- for (long i = 0; i < n%3; ++i)
- ans += a[0], a.pop_front();
- while (a.size())
- {
- ans += a[1]+a[2];
- for (long i = 0; i < 3; ++i)
- a.pop_front();
- }
- cout << ans << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment