fork(1) download
  1. #include <bits/stdc++.h>
  2. #define pi 3.14159265359
  3. using namespace std;
  4.  
  5. int main() {
  6. int N;
  7. cin >> N;
  8. vector<int> A(N);
  9. long long ans =0, St =0;
  10. for(int i =0; i < N; i++) {
  11. cin >> A[i];
  12. St +=A[i];}
  13. if(N%2 != 0) {N++; A.push_back(0);}
  14. multiset<int> S;
  15. for(int i =0; i < N/2; i++) {
  16. ans +=A[2*i];
  17. S.insert(A[2*i]);
  18. if(A[2*i+1] > *S.begin()) {
  19. ans +=A[2*i+1]-*S.begin();
  20. S.erase(S.begin());
  21. S.insert(A[2*i+1]);}
  22. }
  23. cout << ans << " " << St-ans << "\n";
  24. return 0;}
Success #stdin #stdout 0s 3436KB
stdin
5
3 1 2 4 1
stdout
8 3