sort(books.begin(),books.end()); //Groups books by same author together. Within the same groups, books are sorted from smallest happiness to largest happiness.
for(constauto& book : books) {
if(book.first==prev) {
rem+=book.second;
} else {
smallest.push_back(book.second);
prev=book.first;
}
}
//pick smallest book from each author
sort(smallest.begin(),smallest.end()); //sort these books from smallest to largest.