Advertisement
MegaVerkruzo

Untitled

Dec 10th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <cstdio>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <math.h>
  8.  
  9. using namespace std;
  10.  
  11. int main() {
  12. freopen("input.txt", "r", stdin);
  13. int n, m;
  14. cin >> n;
  15. vector<pair<int, int>> a;
  16. for (int i = 0; i < n; ++i) {
  17. int x, y;
  18. cin >> x >> y;
  19. a.push_back({x, y});
  20. }
  21. sort(a.begin(), a.end());
  22. stack<pair<int, int>> st;
  23. vector<long long> ans;
  24. int b = 0;
  25. int cnt = 0;
  26. for (int i = 0; i < n; ++i) {
  27. if (a[i].second == -1) {
  28. b--;
  29. } else {
  30. b++;
  31. }
  32.  
  33. if (b < 0) {
  34. b = 0;
  35. cnt++;
  36. } else {
  37. if (a[i].second == -1) {
  38. ans.push_back(ceil((a[i].first - st.top().first) / 2.0));
  39. st.pop();
  40. } else {
  41. st.push({a[i].first, i});
  42. }
  43. }
  44. }
  45. cnt += st.size();
  46. cin >> m;
  47. for (int i = 0; i < m; ++i) {
  48. int x;
  49. cin >> x;
  50. if (upper_bound(ans.begin(), ans.end(), x) == ans.end()) {
  51. cout << cnt << "\n";
  52. } else {
  53. cout << cnt + (ans.size() - (upper_bound(ans.begin(), ans.end(), x) - ans.begin())) * 2 << "\n";
  54. }
  55. }
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement