Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdio.h>
  4. #include "optimization.h"
  5. #include <assert.h>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     int n, k, a, b;
  11.     n = readInt();
  12.     k = readInt();
  13.     int Left[n];
  14.     int Right[n];
  15.     for (int i = 0; i < n; ++i) {
  16.         a = readInt();
  17.         b = readInt();
  18.         Left[i] = min(a, b);
  19.         Right[i] = max(a, b);
  20.     }
  21.  
  22.     sort(Left, Left + n);
  23.     sort(Right, Right + n);
  24.  
  25.  
  26.     for (int i = 0, x, count = 0; i < k; ++i) {
  27.         x = readInt();
  28.         int left = 0, right = n - 1, middle;
  29.         while (left <= right) {
  30.             middle = (left + right) / 2;
  31.             if (Left[middle] > x)
  32.                 right = middle - 1;
  33.             else
  34.                 left = middle + 1;
  35.         }
  36.         count = right + 1;
  37.  
  38.         left = 0;
  39.         right = n - 1;
  40.         while (left <= right) {
  41.             middle = (left + right) / 2;
  42.             if (Right[middle] < x)
  43.                 left = middle + 1;
  44.             else
  45.                 right = middle - 1;
  46.         }
  47.         count -= right + 1;
  48.         writeInt(count);
  49.         writeChar(' ');
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement