Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define SEND
  5. #define ll long long
  6. #define ld long double
  7. #define pb push_back
  8. #define f first
  9. #define s second
  10. mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
  11.  
  12. struct point {
  13. ld x, y, k;
  14. };
  15.  
  16. ld get_k(ld x1, ld y1, ld x2, ld y2) {
  17. if (x1 == x2)return 0;
  18. return (y1 - y2) / (x1 - x2);
  19. }
  20.  
  21. signed main() {
  22. ios::sync_with_stdio(0);
  23. cin.tie(0);
  24. #ifdef SEND
  25. freopen("mountain.in", "r", stdin);
  26. freopen("mountain.out", "w", stdout);
  27. #endif
  28. int n, q;
  29. cin >> n >> q;
  30. point p[n + 1];
  31. ld a = 0, b = 0;
  32. for (int i = 0; i < n; ++i) {
  33. ld d, k;
  34. cin >> d >> k;
  35. p[i] = {a, b, k};
  36. a += d;
  37. b += d * k;
  38. }
  39. p[n] = {a, b, 0};
  40. while (q--) {
  41. ld x, y;
  42. cin >> x >> y;
  43. int pos = 0;
  44. for (int i = 0; i < n + 1; ++i) {
  45. if (p[i].x <= x)pos = i;
  46. }
  47. int pos1 = pos;
  48. if (pos1 < n)pos1++;
  49. pos--;
  50. while (pos >= 0 && get_k(p[pos].x, p[pos].y, x, y) >= p[pos].k) {
  51. pos--;
  52. }
  53. ll ans1 = p[pos + 1].x;
  54. while (pos1 < n && get_k(p[pos1].x, p[pos1].y, x, y) <= p[pos1].k) {
  55. pos1++;
  56. }
  57. ll ans2 = p[pos1].x;
  58. cout << ans1 << " " << ans2 << endl;
  59. }
  60. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement