This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
ifstream in("in.in");
ofstream out("out.out");
#else
#define in cin
#define out cout
#endif
const int nmax = 200005;
int n,a[nmax],q;
pair<int,int> get_nr(int x) {
int nr = 1;
while(x%2 == 0) {
nr = nr * 2;
x /= 2;
}
return {nr,x};
}
int answer(int x) {
for (int i = 1; i <= n; i++) {
auto val = get_nr(a[i]);
if (val.first < x) {
x -= val.first;
} else {
return val.second;
}
}
return -1;
}
int main() {
in >> n;
for (int i = 1; i <= n; i++) {
in >> a[i];
}
in >> q;
for (int i = 1; i <= q; i++) {
int x;
in >> x;
out << answer(x) << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |