-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHussain_Set.cpp
More file actions
47 lines (40 loc) · 804 Bytes
/
Hussain_Set.cpp
File metadata and controls
47 lines (40 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Dabananda Mitra, CSE (2019-20), ISTT.
// Email: imdmitra@outlook.com
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define TLE \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
void Solution() {
ll n, m, in;
cin >> n >> m;
ll arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
queue<ll> q;
ll ans, count = 0, current, end = n - 1;
while (m--) {
cin >> current;
while (count != current) {
if (end >= 0 && (q.empty() || (arr[end] >= q.front()))) {
ans = arr[end];
end--;
} else {
ans = q.front();
q.pop();
}
q.push(ans / 2);
count++;
}
cout << ans << endl;
}
}
int main() {
TLE;
Solution();
return 0;
}