Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <unordered_set>
- #include <set>
- #include <algorithm>
- using namespace std;
- struct Book {
- unsigned int score;
- unsigned int id;
- };
- // For Hash Map
- struct Hash {
- size_t operator() (const Book &book) const {
- return size_t(book.id) ^ size_t(book.score);
- }
- };
- inline bool operator == (Book const& lhs, Book const& rhs)
- {
- return (lhs.id == rhs.id) && (lhs.score == rhs.score);
- }
- struct Library {
- unsigned int tts; // How many days do signup process takes
- unsigned int bpd; // Books per day
- unsigned int score; // Avg books the lib can send
- unsigned int id; // id of library which came from the input
- };
- using veci = std::vector<int>;
- using vecb = std::vector<Book>;
- using veclib = std::vector<Library>;
- std::vector<veci> booksPerLib;
- vecb books;
- veclib libraries;
- std::unordered_set<Book, Hash> sentBooks;
- int D; // Days for scanning
- void sortLibraries(veclib &vec) {
- std::sort(libraries.begin(), libraries.end(),
- [](const Library &a, const Library &b) -> bool {
- return a.score > b.score;
- });
- }
- int main(int argc, char **argv) {
- int bookCount, libraryCount;
- cin >> bookCount >> libraryCount >> D;
- books.resize(bookCount);
- for (size_t i = 0; i < bookCount; ++i)
- {
- cin >> books[i].score;
- books[i].id = i;
- }
- // Sort the global Books array
- // std::sort(books.begin(), books.end(),
- // [](const Book& a, const Book& b) -> bool
- // {
- // return a.score > b.score;
- // });
- // Input libraries and their respective books
- libraries.resize(libraryCount);
- booksPerLib.resize(libraryCount);
- int libraryBookCount, signupDays, booksPerDay;
- for (size_t i = 0; i < libraryCount; ++i)
- {
- cin >> libraryBookCount >> signupDays >> booksPerDay;
- booksPerLib[i].resize(libraryBookCount);
- int thisLibSumBookScore = 0;
- for (size_t j = 0; j < libraryBookCount; ++j)
- {
- cin >> booksPerLib[i][j];
- thisLibSumBookScore += books[booksPerLib[i][j]].score;
- }
- libraries[i].bpd = booksPerDay;
- libraries[i].tts = signupDays;
- libraries[i].score = (D - signupDays) * (thisLibSumBookScore / booksPerDay);
- libraries[i].id = i;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement