Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int B, L, D;
  7. int s[100005];
  8.  
  9. struct Book {
  10.     int id;
  11.     int cost;
  12.     Book(int id_, int cost_) : id(id_), cost(cost_) {}
  13.     bool operator<(const Book& other) const
  14.     {
  15.         if (cost != other.cost)
  16.             return cost < other.cost;
  17.         return id < other.id;
  18.     }
  19. };
  20.  
  21. struct Library {
  22.     int n, t, m;
  23.     vector<Book> books;
  24.            
  25.     void sortBooks()
  26.     {
  27.         sort(books.begin(), books.end());
  28.         reverse(books.begin(), books.end());
  29.     }
  30.  
  31. }lib[100005];
  32.  
  33. int main(int argc, const char * argv[]) {
  34.     scanf("%d %d %d", &B, &L, &D);
  35.     for (int i = 0; i < B; i++) {
  36.         scanf("%d", &s[i]);
  37.     }
  38.     for (int i = 0; i < L; i++)
  39.     {
  40.         scanf("%d %d %d", &lib[i].n, &lib[i].t, &lib[i].m);
  41.         for (int j = 0; j < lib[i].n; j++)
  42.         {
  43.             int id;
  44.             scanf("%d", &id);
  45.             lib[i].books.push_back(Book(id, s[id]));
  46.         }
  47.         lib[i].sortBooks();
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement