Guest User

Untitled

a guest
May 23rd, 2017
1,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef vector <int> vi;
  6. typedef vector<vi> vvi;
  7. typedef pair<int,int> ii;
  8. #define pb push_back
  9. #define INF 1000000000
  10. #define mp make_pair
  11. #define MOD 1000000007
  12. #define F first
  13. #define S second
  14.  
  15.  
  16. int main() {
  17.  
  18. ios::sync_with_stdio(false);
  19. int n,m;
  20. cin >> n >> m;
  21. ll a[n];
  22. for (int i = 0; i < n; i++) cin >> a[i];
  23. sort(a,a+n);
  24. queue<ll> q1;
  25. queue<ll> q2;
  26. for (int i = n-1; i >= 0; i--) q1.push(a[i]);
  27. ll ans[63000005];
  28.  
  29. for (int i = 1; i <= 63000000; i++){
  30. if (q2.empty()){
  31. if (q1.empty()) break;
  32. ll x = q1.front();
  33. q1.pop();
  34. ans[i] = x;
  35. q2.push(x/2);
  36. }
  37. else if (q1.empty()){
  38. ll x = q2.front();
  39. q2.pop();
  40. ans[i] = x;
  41. q2.push(x/2);
  42. }
  43. else {
  44. ll x = q1.front();
  45. ll y = q2.front();
  46. if (x > y){
  47. ans[i] = x;
  48. q2.push(x/2);
  49. q1.pop();
  50. }
  51. else{
  52. ans[i] = y;
  53. q2.push(y/2);
  54. q2.pop();
  55. }
  56. }
  57. }
  58. while (m --){
  59. int q;
  60. cin >> q;
  61. cout << ans[q] << "\n";
  62. }
  63. }
Add Comment
Please, Sign In to add comment