fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <iomanip>
  5. #include <string>
  6. #include <cmath>
  7. #include <map>
  8. #include <unordered_map>
  9. #include <unordered_set>
  10. #include <vector>
  11. #include <queue>
  12. #include <math.h>
  13. #include <stack>
  14. #include <algorithm>
  15. #include <utility>
  16. #include <set>
  17. #define ll long long
  18. #define endl '\n'
  19. #define EPS 1e-15
  20. const ll N = 1e6 + 5;
  21. #define watch(x) cout << #x << " = " << x << endl;
  22. #define all(v) (v).begin(),(v).end()
  23. //cout<<fixed<<setprecision(6);
  24. using namespace std;
  25. void fast() {
  26. std::ios_base::sync_with_stdio(0);
  27. cin.tie(NULL);
  28. cout.tie(NULL);
  29. }
  30. /*void file()
  31.  {
  32.  #ifndef ONLINE_JUDGE
  33.  freopen("mex.in", "r", stdin) ;
  34.  // freopen("output.txt", "w", stdout) ;
  35.  #endif
  36.  }*/
  37. int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 }; // dir array
  38. int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
  39. ll a[N], b[N],c[N], freq[10000], freq2[26], rght[N], lft[N], y[N];
  40.  
  41. ll mod = 1e9 + 7;
  42. string s ;
  43. void printnum(int num ){
  44. if (num <=1){
  45. cout << num ;
  46. return ;
  47. }
  48. printnum(num/2) ;
  49. cout <<num%2 ;
  50. }
  51. int getbit(int num , int idx){
  52. return (num >> idx) & 1 ;
  53. }
  54. int setbit1(int num , int idx){
  55. return num | (1 << idx ) ;
  56. }
  57. int setbit0(int num , int idx){
  58. return num & ~(1 << idx) ;
  59. }
  60. int flibbit(int num , int idx){
  61. return num ^ (1 << idx) ;
  62. }
  63. int firstOne(int num){
  64. if (num == 0) {
  65. return 0;
  66. } else {
  67. int posfri1 = 0;
  68. for (int i = 0; i < 32; i++) {
  69. if (!(num & (1 << i)))
  70. posfri1++;
  71. else
  72. break;
  73. }
  74. return posfri1;
  75. }
  76. }
  77. int firstZero(int num){
  78. if (num == 0) {
  79. return 0;
  80. } else {
  81. int posfri0 = 0;
  82. for (int i = 0; i < 32; i++) {
  83. if ((num & (1 << i)))
  84. posfri0++;
  85. else
  86. break;
  87. }
  88. return posfri0;
  89. }
  90. }
  91. ll n , p , q ;
  92. bool ok (ll mid){
  93. ll x = mid * q ;
  94. ll need = 0 ;
  95. for (int i=0;i<n;i++){
  96. b[i] = a[i] - x ;
  97. }
  98. for (int i=0;i<n;i++){
  99. if(p==q){
  100. return false ;
  101. break;
  102. }
  103. if (b[i] > 0){
  104. need+=(b[i]+(p-q)-1) /(p-q) ;
  105. }
  106.  
  107. }
  108. if (need <= mid )
  109. return true ;
  110. else
  111. return false ;
  112. }
  113. int main() {
  114. fast();
  115.  
  116. cin >> n >> p >> q ;
  117. for (int i=0;i<n;i++){
  118. cin >> a[i] ;
  119. }
  120. sort(a,a+n) ;
  121. ll l = 0 , r= 1e12 , mid , ans ;
  122. while (l <= r){
  123. mid = (l+r)/2 ;
  124. if (ok(mid)){
  125. ans = mid ;
  126. r=mid-1 ;
  127. }else {
  128. l=mid+1 ;
  129. }
  130. }
  131. cout << ans ;
  132. return 0;
  133. }
Success #stdin #stdout 0s 5492KB
stdin
Standard input is empty
stdout
Standard output is empty