tanasaradu

Untitled

Jan 31st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int Nmax = 100005;
  4. int a[Nmax] , n;
  5. int main()
  6. {
  7. cin >> n;
  8. for(int i = 1 ; i <= n ; i++)
  9. cin >> a[i];
  10. sort(a + 1 , a + n + 1 , greater < int > ());
  11. long long mx = 0 , sum = 0;
  12. for(int i = 1 ; i <= n ; i++)
  13. {
  14. sum += a[i];
  15. if(i % 2 == 0)
  16. mx = max(mx , sum);
  17. }
  18. cout << mx << "\n";
  19. return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment