#include #include #include #include #include using namespace std; typedef pair PII; typedef vector> VII; VII aktivnosti (VII a) { VII razpored; int konec=0; while (1) { int j=-1; for (int i=0;i predavalnice(VII predavanja) { sort(predavanja.begin(), predavanja.end()); vector urnik; priority_queue, greater> pq; // min-heap pq.push({predavanja.back().second, -1}); // dummy for (auto p : predavanja) { auto [s,e] = p; auto [konec, x] = pq.top(); if (konec<=s) { pq.pop(); pq.push({e,x}); urnik[x].push_back(p); } else { pq.push({e,urnik.size()}); urnik.push_back({p}); } } return urnik; } int score(VII d) { int x=0, sc=0; for (auto [s,f] : d) { sc+=x*f; x+=s; } return sc; } bool cmpRatio(PII x, PII y) { // x < y //return x.first/x.second < y.first/y.second; //return (double)x.first/x.second < (double)y.first/y.second; return (long long)x.first*y.second < (long long)y.first*x.second; } int trak(VII d) { sort(d.begin(),d.end(),cmpRatio); return score(d); } int main() { VII d = {{60,5}, {27,3}, {1,20}, {32,4}}; cout << trak(d) << endl; sort(d.begin(),d.end()); do { cout << score(d) << " "; } while (next_permutation(d.begin(),d.end())); cout << endl; /* VII predavanja = {{4,10}, {12,15}, {0,3}, {4,7}, {8,11}, {0,7}, {10,15}, {0,3}, {8,11}, {12,15}}; vector urnik = predavalnice(predavanja); for (auto ucilnica : urnik) { for (auto [s,e] : ucilnica) printf("[%d,%d] ",s,e); printf("\n"); } */ /* VII a = {{1,3},{2,4},{2,5},{4,5},{4,7},{6,7},{6,8},{7,12},{8,12},{9,10},{9,11},{11,12},{12,13}}; //VII r = aktivnosti(a); VII r = aktivnosti2(a); printf("%d:",(int)r.size()); for (auto [s,e] : r) printf(" [%d,%d]",s,e); printf("\n"); */ return 0; }