Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int T;
- cin >> T;
- while(T--){
- int N,Q;
- cin >> N >> Q;
- std::vector<int> v;
- std::vector<int> ans;
- for(int i=0;i<N;i++){
- int x;
- cin >> x;
- v.push_back(x);
- }
- std::vector<int> q;
- int till =0;
- for(int i=0;i<Q;i++){
- int x;
- cin >> x;
- if(x>till){
- till=x;
- }
- q.push_back(x);
- }
- bool chosen[v.size()+1]={0};
- int maxa = 0;
- for(int i=0;i<till;i++){
- maxa=max(maxa,v[i]);
- ans.push_back(maxa);
- }
- for(int i=0;i<q.size();i++){
- cout << ans[q[i]-1] << endl;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment