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;
const int N = 500*1000+5;
long long c[N],p[N];
long long v[N],d[N];
bool cmp(pair<long long, long long> a, pair<long long,long> b){
if(a.first>b.first) return a.first>b.first;
if(a.first<b.first) return a.first>b.first;
return a.second<b.second;
}
int main(){
ios_base::sync_with_stdio(false);
int n,m,k;
cin>>n>>m>>k;
multiset<pair<long long,long long> > ms;
for(int i = 1;i<=n;i++){
cin>>c[i]>>p[i];
ms.insert({p[i],c[i]});
}
vector<pair<long long,long long> > all;
for(int i = 1;i<=m;i++){
cin>>v[i]>>d[i];
all.push_back({v[i],d[i]});
}
sort(all.begin(),all.end(),cmp);
int qn = k;
long long ans = 0;
for(int i = 0;i<all.size();i++){
if(!qn) break;
long long x = all[i].second;
if(ms.lower_bound({x,0}) == ms.end()) continue;
pair<long long,long long> u = *ms.lower_bound({x,0});
if(u.first>=x){
if(all[i].first-u.second>0){
ans-=u.second;
ans+=all[i].first;
ms.erase(ms.find(u));
qn--;
}
}
}
cout<<ans<<endl;
return 0;
}
Compilation message (stderr)
hot.cpp: In function 'int main()':
hot.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<all.size();i++){
~^~~~~~~~~~~
# | 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... |