fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <climits>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(0);
  11. int m, n;
  12. cin >> m >> n;
  13. vector<int> nums(m);
  14. for(int i = 0; i < m; i++){
  15. cin >> nums[i];
  16. }
  17. multiset<int> blackBox;
  18. blackBox.insert(INT_MAX);
  19. auto it = blackBox.begin();
  20. for(int i = 0; i < n; i++){
  21. int req;
  22. cin >> req;
  23. for(int j = blackBox.size() - 1; j < req; j++){
  24. blackBox.insert(nums[j]);
  25. if(nums[j] < *it) it--;
  26. }
  27. cout << *it << endl;
  28. it++;
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 4520KB
stdin
Standard input is empty
stdout
Standard output is empty