# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210118 | 2020-03-16T15:04:44 Z | mr_stefan | Hotel (CEOI11_hot) | C++14 | 0 ms | 0 KB |
#include <iostream> #include <set> using namespace std; const int VAL=500005; int N, M, NRO, i, j; int dif[VAL]; long long ANS; struct camera { int cost, cap; }; camera C[VAL], A; bool operator < (const camera &X, const camera &Y) { if (X.cap!=Y.cap) return X.cap<Y.cap; return X.cost<Y.cost; } set <camera> H; set <camera> :: iterator it; struct oferta { int pret, dim; }; oferta O[VAL]; bool cmpO(oferta A, oferta B) { return A.pret>B.pret; } int main() { cin >> N >> M >> NRO; for (i=1; i<=N; i++) { cin >> C[i].cost >> C[i].cap; H.insert(C[i]); } for (i=1; i<=M; i++) cin >> O[i].pret >> O[i].dim; sort(O+1, O+M+1, cmpO); for (i=1; i<=M; i++) { A.cost=0; A.cap=O[i].dim; it=H.upper_bound(A); if (it==H.end()) continue; A=*it; dif[i]=O[i].pret-A.cost; H.erase(it); //cout << O[i].pret << " " << A.cost << '\n'; } sort(dif+1, dif+M+1); for (i=M; i>M-NRO; i--) if (dif[i]>0) ANS+=dif[i]; cout << ANS << '\n'; return 0; }