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;
#define int long long
const int mxN = (int)5e5+10;
int n, m, k, x, y;
array<int,2> a[mxN];
int32_t main(){
cin >> n >> m >> k; multiset<pair<int,int>> Ms;
while(n--) cin >> x >> y, Ms.insert({y,x});
for(int i = 0; i < m; i++) cin >> a[i][0] >> a[i][1];
multiset<int,greater<>> S; int ans = 0; sort(a,a+m);
for(int i = m-1; i >= 0; i--){
auto itr=Ms.lower_bound({a[i][1],0});
if(itr!=end(Ms) and itr->second < a[i][0])
S.insert(a[i][0]-itr->second), Ms.erase(itr);
}
while(k-- and size(S)) ans+=max(0ll,*begin(S)), S.erase(begin(S));
cout << ans;
}
# | 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... |