Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- int t = 1000001;
- struct contest{
- int start;
- int end;
- };
- bool contestcomp(contest a, contest b) {
- return ((a.start < b.start) ? 1:0);
- };
- int main()
- {
- ios::sync_with_stdio(false);
- int N, V, W; //N = contests, V = V wormholes, W = W wormholes
- cin >> N >> V >> W;
- contest contests[N];
- for(int i = 0; i < N; i++)
- cin >> contests[i].start >> contests[i].end;
- sort(contests, contests + N, contestcomp);
- int X[V]; //Wormhole V starting times;
- int Y[W]; //Wormhole W ending times;
- for(int i = 0; i < V; i++)
- cin >> X[i];
- sort(X, X + V);
- for(int i = 0; i < W; i++)
- cin >> Y[i];
- sort(Y, Y + W);
- //Scanning complete
- int k = 0;
- for(int i = 0; i < N; i++) //iterate through contests;
- {
- int beststart = -1;
- for(k = 0; k < V; k++)
- {
- if(X[k] <= contests[i].start)
- beststart = X[k];
- else{
- k--;
- break;
- }
- }
- int bestend = -1;
- for(int j = 0; j < W; j++)
- {
- if(Y[j] >= contests[i].end){
- bestend = Y[j];
- break;
- }
- }
- if(beststart != -1 & bestend != -1)
- t = min(t, bestend - beststart + 1);
- }
- cout << t;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement