Advertisement
Emiliatan

a450

Jun 16th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. /* a450             */
  2. /* AC (0.8s, 3.9MB) */
  3. #include <cstdio>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const int MAXN = 1000001;
  9.  
  10. int N, Q, l, r, a, b;
  11. int hight[MAXN];
  12.  
  13. int main()
  14. {
  15.     scanf("%d %d", &N, &Q);
  16.     for(int i = 0; i < N; ++i) scanf("%d", hight + i);
  17.     sort(hight, hight + N);
  18.     while(Q--)
  19.     {
  20.         scanf("%d %d", &a, &b);
  21.         l = lower_bound(hight, hight + N, a) - hight;
  22.         r = upper_bound(hight, hight + N, b) - hight;
  23.         if(r - l > 0) printf("%d\n", r - l);
  24.         else puts("The candies are too short");
  25.     }
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement