C. Fly

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n−2n−2 intermediate planets. Formally: we number all the planets from 11 to nn. 11 is Earth, nn is Mars. Natasha will make exactly nn flights: 1→2→…n→11→2→…n→1.

Flight from xx to yy consists of two phases: take-off from planet xx and landing to planet yy. This way, the overall itinerary of the trip will be: the 11-st planet →→ take-off from the 11-st planet →→ landing to the 22-nd planet →→ 22-nd planet →→ take-off from the 22-nd planet →→ …… →→ landing to the nn-th planet →→ the nn-th planet →→ take-off from the nn-th planet →→ landing to the 11-st planet →→ the 11-st planet.

The mass of the rocket together with all the useful cargo (but without fuel) is mm tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that 11 ton of fuel can lift off aiaitons of rocket from the ii-th planet or to land bibi tons of rocket onto the ii-th planet.

For example, if the weight of rocket is 99 tons, weight of fuel is 33 tons and take-off coefficient is 88 (ai=8ai=8), then 1.51.5 tons of fuel will be burnt (since 1.5⋅8=9+31.5⋅8=9+3). The new weight of fuel after take-off will be 1.51.5 tons.

Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.

Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.

Input

The first line contains a single integer nn (2≤n≤10002≤n≤1000) — number of planets.

The second line contains the only integer mm (1≤m≤10001≤m≤1000) — weight of the payload.

The third line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤10001≤ai≤1000), where aiai is the number of tons, which can be lifted off by one ton of fuel.

The fourth line contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤10001≤bi≤1000), where bibi is the number of tons, which can be landed by one ton of fuel.

It is guaranteed, that if Natasha can make a flight, then it takes no more than 109109 tons of fuel.

Output

If Natasha can fly to Mars through (n−2)(n−2) planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number −1−1.

It is guaranteed, that if Natasha can make a flight, then it takes no more than 109109 tons of fuel.

The answer will be considered correct if its absolute or relative error doesn't exceed 10−610−6. Formally, let your answer be pp, and the jury's answer be qq. Your answer is considered correct if |p−q|max(1,|q|)≤10−6|p−q|max(1,|q|)≤10−6.

Examples

input

Copy

2
12
11 8
7 5

output

Copy

10.0000000000

input

Copy

3
1
1 4 1
2 5 3

output

Copy

-1

input

Copy

6
2
4 6 3 3 5 6
2 6 3 6 5 3

output

Copy

85.4800000000

Note

Let's consider the first example.

Initially, the mass of a rocket with fuel is 2222 tons.

  • At take-off from Earth one ton of fuel can lift off 1111 tons of cargo, so to lift off 2222 tons you need to burn 22 tons of fuel. Remaining weight of the rocket with fuel is 2020 tons.
  • During landing on Mars, one ton of fuel can land 55 tons of cargo, so for landing 2020 tons you will need to burn 44 tons of fuel. There will be 1616 tons of the rocket with fuel remaining.
  • While taking off from Mars, one ton of fuel can raise 88 tons of cargo, so to lift off 1616 tons you will need to burn 22 tons of fuel. There will be 1414 tons of rocket with fuel after that.
  • During landing on Earth, one ton of fuel can land 77 tons of cargo, so for landing 1414 tons you will need to burn 22 tons of fuel. Remaining weight is 1212 tons, that is, a rocket without any fuel.

In the second case, the rocket will not be able even to take off from Earth.

思路:二分燃料重量

#include <cstdio>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <iostream>
#define ll long long
#define INF 0x3f3f3f
using namespace std;
const int N=1000+1000;
double a[N],b[N];
double m;
int n;
int ok(double x)
{double fuel,w,cost;int i;fuel=x;w=m+fuel;cost=w/(a[1]*1.0);fuel-=cost;if(fuel<=0) return 0;for(i=2;i<=n;i++){w=m+fuel;cost=w/(b[i]*1.0);fuel-=cost;if(fuel<=0) return 0;w=m+fuel;cost=w/(a[i]*1.0);fuel-=cost;if(fuel<=0) return 0;}w=m+fuel;cost=w/(b[1]*1.0);fuel-=cost;if(fuel<0) return 0;return 1;
}
int main()
{int i;int flag=0;double l,r,mid;scanf("%d",&n);scanf("%lf",&m);for(i=1;i<=n;i++) scanf("%lf",&a[i]);for(i=1;i<=n;i++) scanf("%lf",&b[i]);l=1.0;r=10000000000.0;while(r-l>=0.000001){mid=(l+r)/2.0;if(ok(mid)){r=mid;flag=1;}else l=mid;}if(flag==0) printf("-1\n");else printf("%lf\n",mid);return 0;
}

Codeforces Round #499 (Div. 2) 1011 C. Fly 二分相关推荐

  1. Codeforces Round #499 (Div. 1) Solution

    Codeforces Round #499 (Div. 1) Solution https://codeforces.com/contest/1010 为啥我\(\rm Div.1\)能\(A4\)题 ...

  2. Codeforces Round #725 (Div. 3) G. Gift Set 二分

    传送门 文章目录 题意: 思路: 题意: 有两种物品分别有x,yx,yx,y个,每次可以从一个拿出aaa个,另一个拿出bbb个分成一组,问最多能分成多少组. 思路: 这个题有一个显然的单调性,所以二分 ...

  3. 7-27 Codeforces Round #499 (Div. 2)

    C. Fly 链接:http://codeforces.com/group/1EzrFFyOc0/contest/1011/problem/C 题型:binary search .math. 题意:总 ...

  4. Codeforces Round #499 (Div. 2) : C. Fly

    题目链接:嘻嘻嘻 题目大意:不想说 解题思路:很容易就能想到ans = ret * m - m,   ret =  ,    然而long long 也装不下这个大数,如何处理呢?我们可以求出1 / ...

  5. Codeforces Round #499 (Div. 2) Problem-A-Stages(水题纠错)

    CF链接  http://codeforces.com/contest/1011/problem/A Natasha is going to fly to Mars. She needs to bui ...

  6. Codeforces Round #499 (Div. 2): F. Mars rover(DFS)

    题意:给你一个门电路(包含XOR.OR.AND.NOT.IN五种),这个门电路构成了一棵树,其中1号是输出端(根),所有的叶子都是输入端,给出每个节点(门)的功能以及输入端的输入(是0还是1),求出在 ...

  7. Codeforces Round #321 (Div. 2) Kefa and Company 二分

    原题链接:http://codeforces.com/contest/580/problem/B 题意: 给你一个集合,集合中的每个元素有两个属性,$m_i,s_i$,让你求个子集合,使得集合中的最大 ...

  8. Codeforces Round #202 (Div. 1) A. Mafia 【二分】

    A. Mafia time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  9. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

最新文章

  1. 软件开发 自由职业_自由职业? 这里有7个可以出售软件开发服务的地方
  2. 自然灾害能否被利用?
  3. 汇编 cmp_ARM汇编语言入门(二)
  4. linux中更改文件所有者
  5. syntax error: unexpected end of file
  6. anchor译中文_anchor的意思在线翻译,解释anchor中文英文含义,短语词组,音标读音,例句,词源,同义词【澳典网ODict.Net】...
  7. Taro+react开发(32) Please use the ‘new‘ operator, this DOM object constructor cannot be called as a fu
  8. java中session源码_Spring Session原理及源码分析
  9. 深度学习(四十一)cuda8.0+ubuntu16.04+theano、caffe、tensorflow环境搭建
  10. 2015 圣诞 限免软件分享
  11. CentOS6.5配置网易163做yum源
  12. 安装虚拟环境和Flask
  13. win10设置自定html背景,win10开始菜单背景和图标自定义的方法
  14. Linux源码安装pgadmin4,CentOS7中安装pgAdmin 4
  15. Guava的Splitter和Joiner
  16. 图像处理 - ImageMagick 简单介绍与案例
  17. SwiftUI学习笔记之@State, @Binding
  18. java中无限循环的方法_Java中的无限循环
  19. CocosCreator-精灵动态加载图片资源,实例化精灵
  20. Hbase数据库完全分布式搭建以及java中操作Hbase

热门文章

  1. mysql求月平均_mysql求平均值
  2. org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
  3. cephadm全功能安装Ceph Pacfic
  4. win10打开计算机代码,Win10开不了机错误代码0xc0000428三种解决方法
  5. 记录HRegNet工程的环境配置问题
  6. Kepware通过网络配置三菱FX5U型号PLC的方法
  7. 解决ipad uiwebview显示网页超过屏幕宽度
  8. java 写字板源代码_基于JAVA的模拟写字板的设计与实现(含录像)
  9. [CF_GYM102900L]Traveling in the Grid World
  10. Linux日常命令及理解