Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int t = 1000001;
  8.  
  9. struct contest{
  10. int start;
  11. int end;
  12. };
  13.  
  14. bool contestcomp(contest a, contest b) {
  15. return ((a.start < b.start) ? 1:0);
  16. };
  17.  
  18.  
  19.  
  20. int main()
  21. {
  22. ios::sync_with_stdio(false);
  23. int N, V, W; //N = contests, V = V wormholes, W = W wormholes
  24. cin >> N >> V >> W;
  25. contest contests[N];
  26.  
  27. for(int i = 0; i < N; i++)
  28. cin >> contests[i].start >> contests[i].end;
  29.  
  30. sort(contests, contests + N, contestcomp);
  31.  
  32. int X[V]; //Wormhole V starting times;
  33. int Y[W]; //Wormhole W ending times;
  34.  
  35. for(int i = 0; i < V; i++)
  36. cin >> X[i];
  37.  
  38. sort(X, X + V);
  39.  
  40. for(int i = 0; i < W; i++)
  41. cin >> Y[i];
  42.  
  43. sort(Y, Y + W);
  44.  
  45. //Scanning complete
  46.  
  47. int k = 0;
  48. for(int i = 0; i < N; i++) //iterate through contests;
  49. {
  50. int beststart = -1;
  51. for(k = 0; k < V; k++)
  52. {
  53. if(X[k] <= contests[i].start)
  54. beststart = X[k];
  55. else{
  56. k--;
  57. break;
  58. }
  59. }
  60. int bestend = -1;
  61. for(int j = 0; j < W; j++)
  62. {
  63. if(Y[j] >= contests[i].end){
  64. bestend = Y[j];
  65. break;
  66. }
  67. }
  68. if(beststart != -1 & bestend != -1)
  69. t = min(t, bestend - beststart + 1);
  70.  
  71. }
  72. cout << t;
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement