Iamtui1010

book.cpp

Jan 12th, 2022
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<algorithm>
  4. #include<deque>
  5.  
  6. #define long long long
  7. #define nln '\n'
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     cin.tie(0)->sync_with_stdio(0);
  14.     cout.tie(0)->sync_with_stdio(0);
  15.     //freopen("book.inp", "r", stdin);
  16.     long n;
  17.     cin >> n;
  18.     deque<long> a(n);
  19.     for (auto &i :a)
  20.         cin >> i;
  21.     sort(a.begin(), a.end());
  22.     long ans = 0;
  23.     if (n % 3 != 0)
  24.         for (long i = 0; i < n%3; ++i)
  25.             ans += a[0], a.pop_front();
  26.  
  27.     while (a.size())
  28.     {
  29.         ans += a[1]+a[2];
  30.         for (long i = 0; i < 3; ++i)
  31.             a.pop_front();
  32.     }
  33.     cout << ans << nln;
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment