A. Stock Arbitraging

A. Stock Arbitraging
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Welcome to Codeforces Stock Exchange! We’re pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you’ll still be able to make profit from the market!

In the morning, there are ?
opportunities to buy shares. The ?-th of them allows to buy as many shares as you want, each at the price of ??

bourles.

In the evening, there are ?
opportunities to sell shares. The ?-th of them allows to sell as many shares as you want, each at the price of ??

bourles. You can’t sell more shares than you have.

It’s morning now and you possess ?

bourles and no shares.

What is the maximum number of bourles you can hold after the evening?
Input

The first line of the input contains three integers ?,?,?
(1≤?≤30, 1≤?≤30, 1≤?≤1000

) — the number of ways to buy the shares on the market, the number of ways to sell the shares on the market, and the number of bourles you hold now.

The next line contains ?
integers ?1,?2,…,?? (1≤??≤1000); ?? indicates the opportunity to buy shares at the price of ??

bourles.

The following line contains ?
integers ?1,?2,…,?? (1≤??≤1000); ?? indicates the opportunity to sell shares at the price of ??

bourles.
Output

Output a single integer — the maximum number of bourles you can hold after the evening.
Examples
Input
Copy

3 4 11
4 2 5
4 4 5 4

Output
Copy

26

Input
Copy

2 2 50
5 7
4 2

Output
Copy

50

Note

In the first example test, you have 11
bourles in the morning. It’s optimal to buy 5 shares of a stock at the price of 2 bourles in the morning, and then to sell all of them at the price of 5 bourles in the evening. It’s easy to verify that you’ll have 26

bourles after the evening.

In the second example test, it’s optimal not to take any action.

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n,m,r;
    cin>>n>>m>>r;
    int a[40];
    int b[40];
    int minn=0;
    int amax=0;
    int sum=0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    minn=a[0];
    for(int i=0; i<n; i++)
    {

        if(a[i]<minn)
            minn=a[i];

    }
    for(int i=0; i<m; i++)
    {
        cin>>b[i];
        amax=max(b[i],amax);
    }
    sort(a,a+n);
    sort(b,b+m,cmp);
    if(minn>=amax)
    {
        sum=r;
        cout<<sum<<endl;
    }
    else
    {
        sum=(r/a[0])*b[0]+r%a[0];
        cout<<sum<<endl;
    }
    return 0;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值