The_Law

Untitled

Apr 12th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. multiset<int> s;
  8.  
  9. int32_t main()
  10. {
  11.     ios_base::sync_with_stdio(false);
  12.  
  13.     freopen("A.in", "r", stdin);
  14.  
  15.     int n, x, y;
  16.     scanf("%d%d%d", &n, &x, &y);
  17.  
  18.     for (int i = 0; i < n; ++i)
  19.     {
  20.         int curr;
  21.         scanf("%d", &curr);
  22.         s.insert(curr);
  23.     }
  24.  
  25.     int ans = 0;
  26.  
  27.     while (*(--s.end()) > 0)
  28.     {
  29.         int l = 0, r = *(--s.end());
  30.  
  31.         while(r - l > 1)
  32.         {
  33.             int m = l + (r - l) / 2;
  34.  
  35.             if (*(--s.end()) - x * m > 0 && *(--s.end()) - x * m > *(----s.end()) - y * m)
  36.                 l = m;
  37.             else
  38.                 r = m;
  39.         }
  40.  
  41.         int curr;
  42.  
  43.         for (set<int>::iterator i = s.begin(); i != s.end(); ++i)
  44.         {
  45.             curr = *(i) - y * r;
  46.             s.erase(i);
  47.             s.insert(curr);
  48.         }
  49.  
  50.         curr = *(--s.end()) - (x - y) * r;
  51.         s.erase(--s.end());
  52.         s.insert(curr);
  53.  
  54.         ans += r;
  55.     }
  56.  
  57.     printf("%d", &ans);
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment