classSolution { public: intstoreWater(vector<int>& bucket, vector<int>& vat){ int n = bucket.size(), cnt = 0, res = INT_MAX; for(int i = 0; i < n ; i ++) if(!bucket[i] && vat[i]) bucket[i] ++ , cnt ++;
auto cmp = [](const pair<int, int>& a, const pair<int, int>& b){ return a.first < b.first;}; priority_queue< pair<int, int>, vector<pair<int, int>>, decltype(cmp) > pq(cmp); for(int i = 0; i < n; i ++) if(vat[i]) pq.push(make_pair(ceil(vat[i] / (double)bucket[i]), i)); while(!pq.empty()){ auto top = pq.top(); pq.pop(); res = min(res, cnt + top.first); bucket[top.second] ++; pq.push(make_pair(ceil(vat[top.second] / (double)(bucket[top.second])), top.second)); cnt ++; if(cnt >= res) break; } return res == INT_MAX ? 0 : res; } };