fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. int main() {
  7. int n, k; cin >> n >> k;
  8. vector<int> vec(n);
  9. for(int i = 0; i < n; i++) {
  10. int element; cin >> element;
  11. vec.push_back(element);
  12. }
  13.  
  14. priority_queue<int> pq(less<int>(), vec); // O(N) instead of O(NlogN)
  15. int count= 0;
  16. while(k--) {
  17. int q; cin >> q;
  18. int max;
  19. while(count != q) {
  20. max = pq.top(); // O(1)
  21. pq.pop(); // O(logN)
  22. if(max/2 != 0) {
  23. pq.push(max/2); // O(logN)
  24. }
  25. count++;
  26. }
  27. cout << max << endl;
  28. }
  29.  
  30. // overall time complexity O(N + (klogN))
  31.  
  32. return 0;
  33. }
  34.  
Runtime error #stdin #stdout 0s 4192KB
stdin
Standard input is empty
stdout
Standard output is empty