Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- vector< pair< vector<ll>, vector< pair<ll,ll> > > > libraries;
- ll b, l, d, x; // books, libraries, days
- ll bt[101000] = {};
- ll lt[101000] = {};
- bool cmp(pair< vector<ll>, vector< pair<ll,ll> > > left, pair< vector<ll>, vector< pair<ll,ll> > > right ){
- ll s1 = left.first[3];
- ll s2 = right.first[3];
- double t1 = left.first[1]*left.first[1];
- double t2 = right.first[1]*right.first[1];
- double idx1, idx2;
- idx1 = s1/t1;
- idx2 = s2/t2;
- return idx1 > idx2;
- }
- void scoring(){
- ll score = 0;
- for(int i=0;i<l;i++){
- score = 0;
- sort(libraries[i].second.begin(),libraries[i].second.end(), greater<pair<ll, ll>>());
- ll books_total = (d - libraries[i].first[1]) * libraries[i].first[2];
- for(int j=0;j<books_total and j < libraries[i].first[0] ;j++){
- if(bt[libraries[i].second[j].second]){
- books_total+=1;
- continue;
- }
- score+= libraries[i].second[j].first;
- bt[libraries[i].second[j].second];
- //cout << libraries[i].second[j].first << " ";
- }
- //cout << '\n';
- //cout << i << " " << score << '\n';
- libraries[i].first[3] = score;
- }
- }
- int main(){
- freopen("e_so_many_books.txt", "r", stdin);
- freopen("e_out_3.txt", "w", stdout);
- cin >> b >> l >> d;
- ll book_scores[b+5];
- for(int i=0;i<b;i++){
- cin >> book_scores[i];
- }
- for(int i=0;i<l;i++){
- pair< vector<ll>, vector< pair<ll,ll> > > dummy;
- cin >> x;
- dummy.first.emplace_back(x); // number of books
- cin >> x;
- dummy.first.emplace_back(x);// time of days for signup
- cin >> x;
- dummy.first.emplace_back(x); // number of books to be shipped per day
- dummy.first.emplace_back(0); // initial score index 3
- dummy.first.emplace_back(i); // library number
- for(int j=0; j<dummy.first[0];j++){
- cin >> x;
- dummy.second.emplace_back(book_scores[x],x);
- }
- libraries.emplace_back(dummy);
- }
- cout << l << '\n';
- for(auto li: libraries){
- scoring();
- sort(libraries.begin(), libraries.end(), cmp);
- for(int i =0; i<l;i++){
- if(lt[libraries[i].first[4]]) continue;
- lt[libraries[i].first[4]] = 1;
- cout << libraries[i].first[4] << ' ' << libraries[i].first[0] << '\n';
- for(auto boo: libraries[i].second){
- cout << boo.second << " ";
- }
- cout << '\n';
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement