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 ll long long
const int mxN=5e5;
int n, m, o, c[mxN], p[mxN], p2[mxN], a[mxN];
vector<int> va[mxN], vb[mxN+1];
priority_queue<int> pq;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> o;
for(int i=0; i<n; ++i)
cin >> c[i] >> p[i];
memcpy(p2, p, 4*n);
sort(p2, p2+n);
for(int i=0; i<n; ++i) {
p[i]=lower_bound(p2, p2+n, p[i])-p2;
va[p[i]].push_back(c[i]);
}
for(int i=0, d, v; i<m; ++i) {
cin >> d >> v;
vb[lower_bound(p2, p2+n, v)-p2].push_back(d);
}
for(int i=0; i<n; ++i)
sort(va[i].begin(), va[i].end());
for(int i=0, k=0; i<n; ++i) {
for(int b : vb[i])
pq.push(b);
for(int j=0; j<va[i].size()&&pq.size()&&pq.top()>va[i][j]; ++j) {
a[k++]=pq.top()-va[i][j];
pq.pop();
}
}
nth_element(a, a+o, a+min(n, m));
cout << accumulate(a, a+o, 0ll);
}
Compilation message (stderr)
hot.cpp: In function 'int main()':
hot.cpp:33:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<va[i].size()&&pq.size()&&pq.top()>va[i][j]; ++j) {
~^~~~~~~~~~~~~
# | 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... |