fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define el cout << '\n'
  5. #define ii pair<ll, ll>
  6. #define fi first
  7. #define se second
  8.  
  9. using namespace std;
  10.  
  11. const int maxn = 4e5;
  12.  
  13. int n;
  14. ii a[2 * maxn + 10];
  15. ll ans = 0;
  16.  
  17. bool cmp(ii a, ii b)
  18. {
  19. return a.se - a.fi < b.se - b.fi;
  20. }
  21.  
  22. int main()
  23. {
  24. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  25. if (fopen("ACM.INP", "r"))
  26. {
  27. freopen("ACM.INP", "r", stdin);
  28. freopen("ACM.OUT", "w", stdout);
  29. }
  30.  
  31. cin >> n;
  32. for (int i = 1; i <= 2 * n; i++)
  33. {
  34. cin >> a[i].fi >> a[i].se;
  35. ans += a[i].fi;
  36. }
  37. sort(a + 1, a + 2 * n + 1, cmp);
  38. for (int i = 1; i <= n; i++)
  39. ans += a[i].se - a[i].fi;
  40. cout << ans;
  41. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty