Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- struct v2
- {
- int a;
- int b;
- };
- bool sort1(v2 a, v2 b){
- if(a.a == b.a)
- return a.b < b.b;
- return a.a < b.a;
- }
- bool sort2(v2 a, v2 b){
- if(a.b == b.b)
- return a.a < b.a;
- return a.b < b.b;
- }
- int main()
- {
- int n, x, y=0;
- cin >> n;
- cin >> x;
- cin >> y;
- vector<v2> cs; // list of competition starts and end times
- for(int i =0;i<n;i++)
- {
- v2 a;
- cin >> a.a;
- cin >> a.b;
- cs.push_back(a);
- }
- vector<int> is; //in wormholes
- vector<int> es; //out wormholes
- for(int i =0;i<x;i++)
- {
- int ax = 0;
- cin >> ax;
- is.push_back(ax);
- }
- for(int i =0;i<y;i++)
- {
- int ax = 0;
- cin >> ax;
- es.push_back(ax);
- }
- //sort in ascending order
- sort(is.begin(), is.end());
- //sort first by end time, then matched ones are sorted by start time in ascending
- sort(cs.begin(), cs.end(), sort2);
- sort(es.begin(), es.end());
- //compare every single to find the best way giving O(n^3) but because the arrays are
- //already sorted we just need to check the first element that fits the condition
- //after this the index is saved so that again in next loop we don't check from the beginning
- int out = 1000000;
- int* dp = new int[x]();
- int p1 =0, p2=0;
- for(int i = 0;i<x;i++)
- {
- for(int ab = p1; ab<n;ab++)
- {
- if(cs[ab].a > is[i])
- {
- // cout << "B" << is[i] << "\n";
- bool tset = false;
- for(int ac = p2;ac<y;ac++)
- {
- // cout << "C" << es[ac] << "\n";
- if(cs[ab].b <= es[ac])
- {
- //cout << "A: " << cs[ab].a << " " << is[i] << " " << es[i] << "\n";
- int time= es[ac] - is[i] + 1;
- if(time < out)
- out = time;
- tset =true;
- break;
- }
- p2 = ac;
- }
- if(tset)
- break;
- }
- p1 = ab;
- //p1++;
- }
- }
- cout << out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement