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>
typedef long long ll;
using namespace std;
struct room { ll c, p; };
bool cmproom(const room &a, const room &b)
{
if (a.c == b.c) return a.p < b.p;
return a.c < b.c;
}
bool cmpoffer(const room &a, const room &b)
{
return a.p < b.p;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<room> r(n), o(m);
for (int i = 0; i < n; i++) cin >> r[i].c >> r[i].p;
sort(r.begin(), r.end(), cmproom);
for (int i = 0; i < m; i++) cin >> o[i].c >> o[i].p;
sort(o.begin(), o.end(), cmpoffer);
multiset<ll, greater<ll>> best;
vector<ll> v;
for (int i = 0, j = 0; i < n; i++)
{
while (j < m && o[j].p <= r[i].p) best.insert(o[j++].c);
if (!best.empty())
{
ll x = *best.begin(); best.erase(best.begin());
v.push_back(x - r[i].c);
}
}
sort(v.begin(), v.end(), greater<ll>());
ll ans = 0, sum = 0;
for (int i = 0; i < min((int)v.size(), k); i++) sum += v[i], ans = max(ans, sum);
cout << ans << "\n";
return 0;
}
# | 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... |