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 Ceil(x,y) ((x+y-1)/y)
  22. #define watch(x) cout << #x << " = " << x << endl;
  23. #define all(v) (v).begin(),(v).end()
  24. //cout<<fixed<<setprecision(6);
  25. using namespace std;
  26. void fast() {
  27. std::ios_base::sync_with_stdio(0);
  28. cin.tie(NULL);
  29. cout.tie(NULL);
  30. }
  31. /*void file()
  32.  {
  33.  #ifndef ONLINE_JUDGE
  34.  freopen("mex.in", "r", stdin) ;
  35.  // freopen("output.txt", "w", stdout) ;
  36.  #endif
  37.  }*/
  38. int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 }; // dir array
  39. int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
  40. ll a[N], b[N],c[N], freq[10000], freq2[26], rght[N], lft[N], y[N];
  41.  
  42. ll mod = 1e9 + 7;
  43. string s ;
  44. void printnum(int num ){
  45. if (num <=1){
  46. cout << num ;
  47. return ;
  48. }
  49. printnum(num/2) ;
  50. cout <<num%2 ;
  51. }
  52. int getbit(int num , int idx){
  53. return (num >> idx) & 1 ;
  54. }
  55. int setbit1(int num , int idx){
  56. return num | (1 << idx ) ;
  57. }
  58. int setbit0(int num , int idx){
  59. return num & ~(1 << idx) ;
  60. }
  61. int flibbit(int num , int idx){
  62. return num ^ (1 << idx) ;
  63. }
  64. int firstOne(int num){
  65. if (num == 0) {
  66. return 0;
  67. } else {
  68. int posfri1 = 0;
  69. for (int i = 0; i < 32; i++) {
  70. if (!(num & (1 << i)))
  71. posfri1++;
  72. else
  73. break;
  74. }
  75. return posfri1;
  76. }
  77. }
  78. int firstZero(int num){
  79. if (num == 0) {
  80. return 0;
  81. } else {
  82. int posfri0 = 0;
  83. for (int i = 0; i < 32; i++) {
  84. if ((num & (1 << i)))
  85. posfri0++;
  86. else
  87. break;
  88. }
  89. return posfri0;
  90. }
  91. }
  92. ll n , p , q ;
  93. bool ok (ll mid){
  94. ll x = mid * q ;
  95. ll need = 0 ;
  96. for (int i=0;i<n;i++){
  97. b[i] = a[i] - x ;
  98. }
  99. for (int i=0;i<n;i++){
  100.  
  101. if (b[i] > 0){
  102. if(p==q){ // ركزى هنا ي مرح هااااااااااااااانم
  103. return false ;
  104. }
  105. need+=(b[i]+(p-q)-1) /(p-q) ;
  106. }
  107.  
  108. }
  109. if (need <= mid )
  110. return true ;
  111. else
  112. return false ;
  113. }
  114. int main() {
  115. fast();
  116. // tesssssssssssssssssssssssssssssssst
  117. cin >> n >> p >> q ;
  118. for (int i=0;i<n;i++){
  119. cin >> a[i] ;
  120. }
  121. sort(a,a+n) ;
  122. ll l = 0 , r= 1e9 , mid , ans=0 ;
  123. while (l <= r){
  124. mid = (l+r)/2 ;
  125. if (ok(mid)){
  126. ans = mid ;
  127. r=mid-1 ;
  128. }else {
  129. l=mid+1 ;
  130. }
  131. }
  132. cout << ans ;
  133. return 0;
  134. }
Success #stdin #stdout 0s 5428KB
stdin
Standard input is empty
stdout
Standard output is empty