-
Notifications
You must be signed in to change notification settings - Fork 0
/
a2.cpp
113 lines (90 loc) · 1.9 KB
/
a2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pll pair<ll,ll>
#define vl vector<ll>
#define vll vector < pll >
#define sl set<ll>
#define mll map<ll,ll>
#define itr :: iterator
#define pf push_front
#define ff first
#define ss second
#define MOD 1000000007
struct edge {
ll A;
ll B;
};
bool edgecompare(edge lhs, edge rhs) { if(lhs.B!=rhs.B)return lhs.B < rhs.B;
else return lhs.A<rhs.A;}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n,m,i,j,k,flag=0,x,y,xx,yy;
vll conb,cone;
vl v,w;
cin>>n>>xx>>yy;
for(i=0;i<n;i++)
{
cin>>x>>y;conb.pb({x,y});cone.pb({y,x});
}
for(i=0;i<xx;i++)
{
cin>>x;v.pb(x);
}
for(i=0;i<yy;i++)
{
cin>>x;w.pb(x);
}
sort(conb.begin(),conb.end());
sort(cone.begin(),cone.end());
sort(v.begin(),v.end());
sort(w.begin(),w.end());
vll itr it;vl itr vit,wit;
vit=v.begin();
wit=w.begin();
mll time;
for(it=conb.begin();it!=conb.end();it++)
{
ll st=it->ff;
while((*vit)<=st)
{
vit++;
if(vit==v.end())break;
}
if(vit!=v.begin()){
vit--;
ll ans=1-(*vit);
time[st]=ans;
}
}
for(it=cone.begin();it!=cone.end();it++)
{
ll en=it->ff;
ll st=it->ss;
while((*wit)<en && wit!=w.end())
{
wit++;
if(wit==w.end())break;
}
if(wit!=w.end() && time.find(st)!=time.end())
{
ll ans=*wit;
time[st]+=ans;
}
else if(time.find(st)!=time.end())
{
time[st]=INT_MAX;
}
}
mll itr mall;ll mi=INT_MAX;
for(mall=time.begin();mall!=time.end();mall++)
{
if(mall->ss < mi)mi=mall->ss;
}
cout<<mi;
return 0;
}