fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int n;
  8. cin>>n;
  9. int a[1005];
  10. for(int i=0;i<n;i++)
  11. cin>>a[i];
  12.  
  13. sort(a,a+n);
  14. int sereja=0,dima=0;
  15.  
  16. if(n%2==0)
  17. {
  18. for(int i=0;i<n;i++)
  19. {
  20. if(i%2==0)
  21. dima+=a[i];
  22. else
  23. sereja+=a[i];
  24. }
  25. }
  26. else
  27. {
  28. for(int i=0;i<n;i++)
  29. {
  30. if(i%2!=0)
  31. dima+=a[i];
  32. else
  33. sereja+=a[i];
  34. }
  35. }
  36.  
  37. cout<<sereja<<' '<<dima;
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
0 0