Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define pb push_back
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- ///freopen("input.txt", "r", stdin);
- ///freopen("output.txt", "w", stdout);
- _test
- {
- ll int n;
- cin>>n;
- vector<ll int> c(n);
- for(auto &e: c) cin>>e;
- ll int k;
- cin>>k;
- vector<ll int> ans, use;
- multiset<ll int> mst;
- for(auto e: c) mst.insert(e);
- ans.pb(k/(*mst.begin()));
- k -= ans.back() * (*mst.begin());
- ll int used = *mst.begin();
- mst.erase(mst.find(c[0]));
- for(int i=1; i<n; i++)
- {
- ll int tmp = 0;
- ll int low=1, high=ans.back(), mid;
- while(low <= high)
- {
- mid = (low + high)/2;
- if((k+used*mid)/(*mst.begin()) >= mid)
- tmp=mid, low=mid+1;
- else
- high=mid-1;
- }
- k += used*tmp;
- used = *mst.begin();
- ans.pb(k/(*mst.begin()));
- mst.erase(mst.find(c[i]));
- k -= ans.back() * used;
- }
- for(auto e: ans) cout<<e<<" ";
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement