1 /*=============================================================================================================================*/
2 /*======================================================Code by Asm.Def========================================================*/
3 /*=============================================================================================================================*/
4 #include <cstdio>
5 #include <iostream>
6 #include <algorithm>
7 #include <cmath>
8 #include <cctype>
9 #include <memory.h>
10 #include <vector>
11 #include <set>
12 #include <string>
13 #include <cstring>
14 #include <map>
15 #include <queue>
16 #include <deque>
17 #include <stack>
18 #include <ctime>
19 #include <iterator>
20 #include <functional>
21 #include <cstdlib>
22 using namespace std;
23 #define forall(it,v) for(__typeof(v.begin()) it = v.begin();it < v.end();++it)
24 #define pb push_back
25 #define REP(i,j,k) for(i = j;i <= k;++i)
26 #define REPD(i,j,k) for(i = j;i >= k;--i)
27 typedef long long LL;
28 #if defined DEBUG
29 FILE *in = fopen("test", "r");
30 #define out stdout
31 #else
32 FILE *in = fopen("qc.in","r");
33 FILE *out = fopen("qc.out","w");
34 #endif
35 template <typename T>
36 void getint(T &x){
37 char c = fgetc(in);
38 while(!isdigit(c))c = fgetc(in);
39 x = c - ‘0‘;
40 while(isdigit(c = fgetc(in)))x = x * 10 + c - ‘0‘;
41 }
42 /*==============================================WORK===========================================================*/
43 const int maxn = (int)2e5 + 4;
44
45 inline void putLL(const LL&x){
46 if(x < 1000000000){fprintf(out, "%d\n", x);return;}
47 int l = x / 1000000000, r = x % 1000000000;
48 fprintf(out, "%d%09d\n", l, r);
49 }
50
51 struct Obj{
52 int w, v, loc;
53 bool operator < (const Obj &b)const{
54 return w > b.w;
55 }
56 }O[maxn] = {{0,0,0}};
57 int n, m, L[maxn], R[maxn], now = 0, Sumcnt[maxn] = {0};
58 LL S, SumV[maxn] = {0};
59 int V[maxn] = {0};//用于计算"价格"前缀和 & 个数前缀和
60 inline LL f(int W){///////////////////////////////////////////////////
61 LL ans = 0; SumV[0] = 0;Sumcnt[0] = 0;
62 int i;
63 if(O[now].w > W) while(now < n && O[now+1].w >= W)
64 ++now, V[O[now].loc] = O[now].v;
65 else while(now && O[now].w < W)
66 V[O[now].loc] = 0, --now;
67 for(i = 1;i <= n;++i)
68 SumV[i] = SumV[i-1] + V[i], Sumcnt[i] = Sumcnt[i-1] + bool(V[i]);
69 for(i = 0;i < m;++i)
70 ans += (SumV[R[i]] - SumV[L[i]-1]) * (Sumcnt[R[i]] - Sumcnt[L[i]-1]);
71 return ans;
72 }
73 int main(){
74 int i, j = 0, k;
75 LL ans, t, t2;
76 int Wcase[maxn] = {0}, Wcnt = 0;
77 getint(n), getint(m), getint(S);
78 for(i = 1;i <= n;++i){
79 getint(O[i].w), getint(O[i].v);
80 O[i].loc = i;
81 }
82 sort(O + 1, O + n + 1);
83 O->w = O[1].w + 1;
84 for(i = 0;i < m;++i)
85 getint(L[i]), getint(R[i]);
86 for(i = 1;i <= n;++i)
87 if(!Wcnt || O[i].w != Wcase[Wcnt-1])
88 Wcase[Wcnt++] = O[i].w;
89 i = 0, j = Wcnt-1;
90 while(i <= j){
91 k = (i + j) >> 1;
92 t = f(Wcase[k]);
93 if(t == S){ans = 0;break;}
94 if(t > S)j = k - 1;
95 else i = k + 1;
96 }
97 ans = S > t ? S - t : t - S;
98 t2 = f(Wcase[i ^ j ^ k]);//i ^ j ^ k表示i和j中不等于k的那一个
99 t2 = S > t2 ? S - t2 : t2 - S;
100 if(t2 < ans)ans = t2;
101 putLL(ans);
102 //----------------------------------------------------------------------------------------------------------------------
103 #if defined DEBUG
104 cout << endl << (double)clock() / CLOCKS_PER_SEC <<endl;
105 #endif
106 return 0;
107 }
108 /*=============================================================================================================================*/