Advertisement
Ankit_132

D

Sep 18th, 2023
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define pb     push_back
  9.  
  10. int main()
  11. {
  12.     ios_base::sync_with_stdio(false);
  13.     cin.tie(NULL);
  14.     cout.tie(NULL);
  15.  
  16.     ///freopen("input.txt", "r", stdin);
  17.     ///freopen("output.txt", "w", stdout);
  18.  
  19.     _test
  20.     {
  21.         ll int n;
  22.         cin>>n;
  23.  
  24.         vector<ll int> c(n);
  25.         for(auto &e: c)     cin>>e;
  26.  
  27.         ll int k;
  28.         cin>>k;
  29.  
  30.         vector<ll int> ans, use;
  31.         multiset<ll int> mst;
  32.  
  33.         for(auto e: c)      mst.insert(e);
  34.  
  35.         ans.pb(k/(*mst.begin()));
  36.         k -= ans.back() * (*mst.begin());
  37.         ll int used = *mst.begin();
  38.         mst.erase(mst.find(c[0]));
  39.  
  40.         for(int i=1; i<n; i++)
  41.         {
  42.             ll int tmp = 0;
  43.             ll int low=1, high=ans.back(), mid;
  44.  
  45.             while(low <= high)
  46.             {
  47.                 mid = (low + high)/2;
  48.  
  49.                 if((k+used*mid)/(*mst.begin()) >= mid)
  50.                     tmp=mid, low=mid+1;
  51.                 else
  52.                     high=mid-1;
  53.             }
  54.  
  55.             k += used*tmp;
  56.  
  57.             used = *mst.begin();
  58.             ans.pb(k/(*mst.begin()));
  59.             mst.erase(mst.find(c[i]));
  60.  
  61.             k -= ans.back() * used;
  62.         }
  63.  
  64.         for(auto e: ans)        cout<<e<<" ";
  65.         cout<<"\n";
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement