The strength value of the small p

Source: Internet
Author: User

Time limit for strength of small p: 10000ms single point time: 1000ms memory limit: 256MB description

Little hi in the virtual world has a small pet small p. The small P has K attributes, and the initial value of each property is AI. Little ho gave small hi a few pills, each pill can raise the small p specify the attribute 1 points. With the property value, we can calculate the strength value of the small P = (C1 (1/B1)) * (C2 (1/B2)) *...* (CK (1/BK)), where CI is the final value of the small P-I property (ai+ pill added attribute). Small Ho is known to give small hi pills a total of n, ask the strength of the small p max can reach?

Input

The first line contains two integer n,k, each representing the number of pills and the number of attributes.

The second behavior is k integer a1-ak, meaning as described earlier.

The third act K integer b1-bk, meaning as described above.

For 30% of data, meet 1<=n<=10, 1<=k<=3

For 100% of data, meet 1<=n<=100000, 1<=k<=10

For 100% of data, meet 1<=ai<=100, 1<=bi<=10

Output

The highest strength value the output small p can achieve.

As long as the relative or absolute error between your results and the correct answer does not exceed 1 per thousand, it is considered the correct output.

Sample input
5 21 13 2
Sample output
2.88
Analysis: After the answer to log found that in fact multiplication into an addition, and then the priority queue simulation can be;
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineVI vector<int>#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)#definePII pair<int,int>Const intmaxn=1e5+Ten;Const intdis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};using namespacestd;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p%mod;p=p*p%mod;q>>=1;}returnF;}intn,m,k,t;Doubleans;structnode{intX,y,id; BOOL operator< (ConstNODE&AMP;P)Const    {        return 1.0/y* (log (x+1)-log (x)) <1.0/p.y* (log (p.x+1)-log (p.x)); }}A[MAXN];p riority_queue<node>p;intMain () {inti,j; scanf ("%d%d",&n,&k); Rep (I,0, K-1) scanf ("%d", &a[i].x), a[i].id=i; Rep (I,0, K-1) scanf ("%d",&a[i].y); Rep (I,0, K-1) P.push (A[i]); Rep (I,0, N-1) {node Q=P.top ();        P.pop (); q.x++,a[q.id].x++;    P.push (q); } ans=1.0; Rep (I,0, K-1) Ans=ans*pow (a[i].x,1.0/a[i].y); printf ("%.7f\n", ans); //System ("pause");    return 0;}

The strength value of the small p

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.