Code for calculating the books dispatched
There are some minor nits about the general code


Separate operators like &gt;&gt; with spaces, that makes the code much easier to read. Also you should separate language constructs like for or while with a space afterwards, to readily separate them from function calls.
You should use range based loops when you already have the vector fully initialized, it is much more concise. 

int numBooks;
std::cin &gt;&gt; numBooks;
std::vector&lt;int&gt; books(numBooks);
for (auto &amp;book : books){
    std::cin &gt;&gt; book;
}

The return 0; at the end is not necessary anymore with modern compilers.
You should prefer pre increment ++book over post increment book++, as the later involves a copy (at least for non trivial data types)
Actually your code itself is way to complicated. Rather than assigning a new vector you can just shrink the old one

int numTaken;
std::cin &gt;&gt; numTaken;
for (int book = 0; book &lt; numTaken; ++book) {
    int bookId;
    std::cin &gt;&gt; bookId;
    std::cout &lt;&lt; books[bookId];
    books.erase(bookId);
}



Full code

#include &lt;iostream&gt;
#include &lt;vector&gt;   

int main() {
    std::ios_base::sync_with_stdio(false);
    size_t numBooks;
    std::cin &gt;&gt; numBooks;
    std::vector&lt;int&gt; books;
    books.reserve(numBooks);
    for (size_t book = 0; book &lt; numBooks; ++book) {
        size_t bookId;
        std::cin &gt;&gt; bookId;
        books.push_back(bookId);
    }

    size_t numBorrowed;
    std::cin &gt;&gt; numBorrowed;
    for (size_t borrow = 0; borrow &lt; numBorrowed; ++borrow) {
        size_t bookId;
        std::cin &gt;&gt; bookId;
        std::cout &lt;&lt; books[bookId] &lt;&lt; "\n";
        books.erase(bookId);
    }
}