# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
117200 | Namnamseo | Hotel (CEOI11_hot) | C++17 | 847 ms | 72520 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
void cppio(){ ios_base::sync_with_stdio(0); cin.tie(0); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()
const int inf = int(1e9) + 10;
int n, m;
const int maxn = int(5e5) + 10;
pp room[maxn];
pp req[maxn];
priority_queue<int> pq[maxn];
set<pp> S;
set<int> on;
int main()
{
int o;
cppio(); cin >> n >> m >> o;
rrep(i, n) { cin >> room[i].x >> room[i].y; }
rrep(i, m) { cin >> req[i].y >> req[i].x; }
sort(room+1, room+n+1);
sort(req+1, req+m+1);
rrep(i, m) {
static int pt = 1;
while(pt<=n && room[pt].y < req[i].x) ++pt;
if(pt > n) break;
pq[pt].push(req[i].y);
}
rrep(i, n) if(pq[i].size()) { S.emplace(pq[i].top() - room[i].x, i); }
rrep(i, n) on.insert(i);
int match = 0;
ll ans = 0;
while(match < o && S.size()) {
auto it = --S.end();
if(it->x < 0) break;
ans += it->x;
int i = it->y;
S.erase(it);
++match;
pq[i].pop();
if(pq[i].size()) {
auto it = on.erase(on.find(i));
if(it == on.end()) continue;
int j = *it;
if(pq[j].size()) S.erase(pp(pq[j].top() - room[j].x, j));
if(pq[i].size() > pq[j].size()) {
swap(pq[i], pq[j]);
}
while(pq[i].size()) {
pq[j].push(pq[i].top());
pq[i].pop();
}
S.emplace(pq[j].top() - room[j].x, j);
}
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |