Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <math.h>
- #include <cstdio>
- using namespace std;
- long long n, m, q;
- vector<long long> u, l, a, f;
- long double fun(long double x) {
- long double ans = 0.0;
- for (long long i = 0; i < n; i++) {
- ans += l[i] / (u[i] + x);
- }
- return ans;
- }
- int main(){
- //freopen("Hello.txt", "w", stdout);
- cout.precision(20);
- long long x;
- cin >> n;
- for (long long i = 0; i < n; i++) {
- cin >> x;
- u.push_back(x);
- }
- for (long long i = 0; i < n; i++) {
- cin >> x;
- l.push_back(x);
- }
- cin >> m;
- for (long long i = 0; i < m-1; i++) {
- cin >> x;
- a.push_back(x);
- }
- for (long long i = 0; i < m; i++) {
- cin >> x;
- f.push_back(x);
- }
- long double s, s2, t, time;
- long long gl, gr;
- time = fun(0);
- cin >> q;
- if (n == 1) {
- while (q--) {
- int x, y;
- cin >> x>> y;
- long double v1, e;
- if (y - x > time) {
- cout<< 0 << endl;
- goto W;
- }
- v1 = l[0] / (y - x);
- e = v1 - u[0];
- if (m == 1 && time > y - x) {
- cout << f.back() << endl;
- goto W;
- }
- /*if (time-y+x==0) {
- cout « 0 « endl;
- goto W;
- }*/
- for (int i = 0; i < m - 1; ++i)
- if (e <= a[i]) {
- cout << f[i] << endl;
- goto W;
- }
- cout << f[m - 1] << endl;
- W:;
- }
- }
- if (m == 1 && n != 1) {
- for (long long i = 0; i < q; i++) {
- cin >> s >> s2;
- t = s2 - s;
- if (t <= time) {
- cout << f[0] << '\n';
- }
- else {
- cout << '0' << '\n';
- }
- }
- }
- else {
- for (long long i = 0; i < q; i++) {
- cin >> s >> s2;
- t = s2 - s;
- gl = -1;
- gr = m;
- while (gr - gl != 1) {
- long long mm = (gr + gl) / 2;
- if (fun(a[mm]) > t) {
- gl = mm;
- }
- else {
- gr = mm;
- }
- }
- if (t <= time) {
- cout << f[gr] << '\n';
- }
- else {
- cout << '0' << '\n';
- }
- }
- }
- //fclose(stdout);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement