Need Help - what's wrong in my solution

Problem Link - https://www.codechef.com/IARCSJUD/problems/BOOKLIST

My code is not getting accepted…
Can someone please tell me the mistake in my code ?

#include<bits/stdc++.h>
int main()
{
    int m;
    std::cin>>m;
    int position[m];
    for(int i=0;i<m;i++)
    {
        std::cin>>position[i];
    }
    int n, b_pos,count=0;
    std::cin>>n;
    for(int i=0;i<n;i++)
    {
        std::cin>>b_pos;
        std::cout<<position[b_pos-1+count]<<"\n";
        count++;
   }
return 0;
}

Hey I Too thought about the same solution at first but maybe this testcase will help you to find why your answer is wrong think about it!! ;D

Input:
3
5 4 2
2
2
1

Expected Output:
4
5

Your codes Output:
4
4
1 Like

Hey ! Got the mistake in my code.
Thank you :smiley: !

Did you got the solution?? I can help you with that… and do share your code if you get the answer:D

Yup, I did get the solution :smiley:
Here’s it

#include<bits/stdc++.h>
#include<vector>
int main()
{
    int m , input;
    std::cin>>m;
    std::vector<int>position;
    for(int i=0;i<m;i++)
    {
        std::cin>>input;
        position.push_back(input);
    }
    int n, b_pos;
    std::cin>>n;
    for(int i=0;i<n;i++)
    {
        std::cin>>b_pos;
        std::cout<<position[b_pos-1]<<"\n";
        position.erase(position.begin() + b_pos -1);
    }
    return 0;
}

Yaa it too came with the same solution!!
I was hoping that there might be some alternate way to do this problem

#include <bits/stdc++.h>
using namespace std;

//https://www.codechef.com/IARCSJUD/problems/BOOKLIST
int main(){
    int M;
    cin >> M;

    vector<int> vec(M + 1);

    for(int i = 1;i <= M; i++){
        cin >> vec[i];
    }

    //here we have N borrowers
    int N;
    cin >> N;

    while(N--){
        int book_pos;
        cin >> book_pos;

        cout << vec[book_pos] << '\n';

        auto it = vec.begin()  + book_pos;
        vec.erase(it);//O(N) time complexity
    }
    //time complexity:10^6 * 10^3 -> 10^9 -> O(N*M)
}