Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.     vector<int> x1;
  8.     vector<int> x2;
  9.     for (int i = 0; i < n; i++) {
  10.         int z;
  11.         cin >> z;
  12.         x1.push_back(z);
  13.         cin >> z;
  14.         x2.push_back(z);
  15.     }
  16.     int s1, s2;
  17.     s1 = x1[0];
  18.     s2 = x2[0];
  19.     for (int i = 1; i < n; i++) {
  20.         if (s1 < x1[i]) {
  21.             s1 = x1[i];
  22.         }
  23.         if (s2 > x2[i]) {
  24.             s2 = x2[i];
  25.         }
  26.     }
  27.     if (s2 - s1 < 0) {
  28.         cout << 0;
  29.     }
  30.     else cout << s2 - s1;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement