#include <algorithm> #include <iostream> #include <cstring> #include <iomanip> #include <cstdlib> #include <climits> #include <cstdio> #include <bitset> #include <string> #include <vector> #include <cctype> #include <stack> #include <queue> #include <deque> #include <cmath> #include <map> #include <set>
#define I inline #define fi first #define se second #define pb push_back #define MP make_pair #define PII pair<int , int> #define PSL pair<string , long long> #define PLL pair<long long , long long> #define all(x) (x).begin() , (x).end() #define copy(a , b) memcpy(a , b , sizeof(b)) #define clean(a , b) memset(a , b , sizeof(a)) #define rep(i , l , r) for (int i = (l); i <= (r); i ++) #define per(i , r , l) for (int i = (r); i >= (l); i --) #define PE(i , x) for(int i = head[x]; i; i = edge[i].last) #define DEBUG(x) std :: cerr << #x << '=' << x << std :: endl
typedef long long ll; typedef unsigned long long ull;
template <class T> inline void read(T &x) { char c = getchar(), f = 0; x = 0; while (!isdigit(c)) f = (c == '-'), c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x = f ? -x : x; }
using namespace std;
const int N = 10000 + 5; const int M = 1000000 + 5; const int HA = 998244353;
ll n , m1 , m2;
struct Jian{ ll bru , num; }J1[M] , J2[M];
struct Dun{ ll bru , num; }d[M];
bool cmp1(Jian a , Jian b) { if(a.bru == b.bru) return a.num < b.num; else return a.bru < b.bru; } bool cmp2(Dun a , Dun b) { if(a.bru == b.bru) return a.num < b.num; else return a.bru < b.bru; }
Jian a[M] , b[M]; Dun c[M];
ll ans1;
void solve1() { copy(a , J1) , copy(b , J2); int pla = 1; per(i , n , 0){ if(a[i].bru <= b[pla].bru) break; if(pla > m2) break; while(a[i].bru > b[pla].bru && a[i].num > 0 && pla <= m2){ if(a[i].num >= b[pla].num){ ll val = a[i].bru - b[pla].bru; val *= b[pla].num; ans1 += val; a[i].num -= b[pla].num , b[pla].num = 0; pla ++; } else { ll val = a[i].bru - b[pla].bru; val *= a[i].num; ans1 += val; b[pla].num -= a[i].num; a[i].num = 0; } } } }
ll ans2;
void solve2() { copy(a , J1) , copy(b , J2) , copy(c , d); int pla = 1; rep(i , 1 , n){ if(pla > m1) break; while(a[i].bru >= c[pla].bru && a[i].num > 0 && pla <= m1){ if(a[i].num >= c[pla].num){ a[i].num -= c[pla].num; c[pla].num = 0; pla ++; } else { c[pla].num -= a[i].num; a[i].num = 0; } } } if(pla <= m1) return ; rep(i , 1 , m2){ if(b[i].bru < 0) continue; else { b[i].bru = 0 , b[i].num = 0x3f3f3f3f; } } b[m2 + 1].bru = 0 , b[m2 + 1].num = 0x3f3f3f3f; pla = 1; per(i , n , 1){ if(a[i].bru <= b[pla].bru) break; while(a[i].bru > b[pla].bru && a[i].num > 0) { if(a[i].num >= b[pla].num){ ll val = a[i].bru - b[pla].bru; val *= b[pla].num; ans2 += val; a[i].num -= b[pla].num; b[pla].num = 0; pla ++; } else { ll val = a[i].bru - b[pla].bru; val *= a[i].num; ans2 += val; b[pla].num -= a[i].num; a[i].num = 0; } } } }
#define LOCAL
int main() { #ifdef LOCAL freopen("panwang.in" , "r" , stdin); freopen("panwang.out" , "w" , stdout); #endif read(n) , read(m1) , read(m2); rep(i , 1 , n) read(J1[i].bru) , read(J1[i].num); rep(i , 1 , m1) read(d[i].bru) , read(d[i].num); rep(i , 1 , m2) read(J2[i].bru) , read(J2[i].num); sort(J1 + 1 , J1 + 1 + n , cmp1); sort(J2 + 1 , J2 + 1 + m2 , cmp1); sort(d + 1 , d + 1 + m1 , cmp2); solve1() , solve2(); printf("%lld\n" , max(ans1 , ans2));
return 0; }
|