tiom4eg

openol G 100

Jan 16th, 2024
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld long double
  9. //#define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define vi vector <int>
  12. #define mi vector <vector <int>>
  13. // Quick functions
  14. #define endl "\n"
  15. #define F first
  16. #define S second
  17. #define all(a) a.begin(), a.end()
  18. #define sz(a) (int)(a.size())
  19. #define pb push_back
  20. #define mp make_pair
  21. // Quick fors
  22. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  23. #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
  24. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  25. #define EACH(e, a) for (auto& e : a)
  26. // Pragmas
  27. #ifndef TIOM4EG
  28. #pragma GCC optimize("O3") // let the chaos begin!
  29. #pragma GCC target("avx,avx2,tune=native")
  30. #pragma GCC comment(linker, "/stack:200000000")
  31. #endif
  32. // PBDS
  33. #include <ext/pb_ds/assoc_container.hpp>
  34. #include <ext/pb_ds/tree_policy.hpp>
  35. #define pbds tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  36. using namespace __gnu_pbds;
  37. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  38. using namespace std;
  39. mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
  40. #define int long long
  41. constexpr int INF = 1e9 + 7, MD = 998244353, MAX = 200007, LG = 19, R = 1 << LG, MOD = 1000000007, MOD2 = 1e9 + 9, B = 256;
  42. const ll INFLL = 1e18 + 7;
  43.  
  44.  
  45. signed main() {
  46.     fastIO;
  47.     int n, a, b; cin >> n >> a >> b;
  48.     vi t(n); EACH(e, t) cin >> e, ++e;
  49.     sort(all(t));
  50.     if (t.back() <= 0) return !(cout << 0);
  51.     if (n == 1) return !(cout << (t[0] + a - 1) / a);
  52.     if (a == b) {
  53.         if (t.back() <= 0) cout << 0;
  54.         else cout << (t.back() + a - 1) / a;
  55.         return 0;
  56.     }
  57.     if (a < b) {
  58.         int d = b - a;
  59.         int l = 0, r = 2 * INF;
  60.         while (l < r - 1) {
  61.             int m = (l + r) / 2, c = 0;
  62.             if (t[n - 1] - b * m > 0) {
  63.                 l = m;
  64.                 continue;
  65.             }
  66.             FOR(i, 0, n) {
  67.                 int w = t[i] - b * m;
  68.                 c += -w / d;
  69.                 if (c >= m) break;
  70.             }
  71.             (c >= m ? r : l) = m;
  72.         }
  73.         cout << r;
  74.     }
  75.     else {
  76.         int d = a - b;
  77.         int l = 0, r = 2 * INF;
  78.         while (l < r - 1) {
  79.             int m = (l + r) / 2, c = 0;
  80.             FOR(i, 0, n) {
  81.                 int w = t[i] - b * m;
  82.                 if (w >= 0) c += (w + d - 1) / d;
  83.                 if (c > m) break;
  84.             }
  85.             (c > m ? l : r) = m;
  86.         }
  87.         cout << r;
  88.     }
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment