Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define SEND
- #define ll long long
- #define ld long double
- #define pb push_back
- #define f first
- #define s second
- mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
- struct point {
- ld x, y, k;
- };
- ld get_k(ld x1, ld y1, ld x2, ld y2) {
- if (x1 == x2)return 0;
- return (y1 - y2) / (x1 - x2);
- }
- signed main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- #ifdef SEND
- freopen("mountain.in", "r", stdin);
- freopen("mountain.out", "w", stdout);
- #endif
- int n, q;
- cin >> n >> q;
- point p[n + 1];
- ld a = 0, b = 0;
- for (int i = 0; i < n; ++i) {
- ld d, k;
- cin >> d >> k;
- p[i] = {a, b, k};
- a += d;
- b += d * k;
- }
- p[n] = {a, b, 0};
- while (q--) {
- ld x, y;
- cin >> x >> y;
- int pos = 0;
- for (int i = 0; i < n + 1; ++i) {
- if (p[i].x <= x)pos = i;
- }
- int pos1 = pos;
- if (pos1 < n)pos1++;
- pos--;
- while (pos >= 0 && get_k(p[pos].x, p[pos].y, x, y) >= p[pos].k) {
- pos--;
- }
- ll ans1 = p[pos + 1].x;
- while (pos1 < n && get_k(p[pos1].x, p[pos1].y, x, y) <= p[pos1].k) {
- pos1++;
- }
- ll ans2 = p[pos1].x;
- cout << ans1 << " " << ans2 << endl;
- }
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement