fork download
  1. /*
  2.   author : [ Godsent ]
  3.   created : 2025.07.29 13:13:47
  4. */
  5.  
  6. #include <bits/stdc++.h>
  7. #define el "\n"
  8. #define int long long
  9. #define ld long double
  10. #define lb ler_bound
  11. #define ub upper_bound
  12. #define fi first
  13. #define se second
  14. #define sz(x) ((int)(x).size())
  15. #define all(v) (v).begin(), (v).end()
  16. #define pb push_back
  17. #define prs(n) fixed << setprecision(n)
  18.  
  19. const int mod = 1e9 + 7;
  20. const int N = 1e5 + 5;
  21. const int INF = 1e18;
  22.  
  23. using namespace std;
  24.  
  25. int n;
  26. int a[N], b[N];
  27.  
  28. int check(int k) {
  29. int total = 0;
  30. for (int i = 0; i < n; i++) {
  31. if (a[i] > k) total += a[i] - k;
  32. if (b[i] < k) total += k - b[i];
  33. }
  34. return total;
  35. }
  36.  
  37. signed main() {
  38. ios_base::sync_with_stdio(false);
  39. cin.tie(0);
  40. cout.tie(0);
  41.  
  42. #ifndef ONLINE_JUDGE
  43. freopen("test.inp", "r", stdin);
  44. freopen("test.out", "w", stdout);
  45. #endif
  46.  
  47. cin >> n;
  48. int l = INF, r = -INF;
  49. for (int i = 0; i < n; i++) {
  50. cin >> b[i];
  51. l = min(l, b[i]);
  52. r = max(r, b[i]);
  53. }
  54.  
  55. for (int i = 0; i < n; i++) {
  56. cin >> a[i];
  57. l = min(l, a[i]);
  58. r = max(r, a[i]);
  59. }
  60.  
  61. while (l < r) {
  62. int m1 = l + (r - l) / 3;
  63. int m2 = r - (r - l) / 3;
  64.  
  65. if (check(m1) < check(m2)) r = m2 - 1;
  66. else l = m1 + 1;
  67. }
  68.  
  69. cout << l << el;
  70.  
  71. return 0;
  72. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
1000000000000000000