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 n opportunities to buy shares. The i-th of them allows to buy as many shares as you want, each at the price of si bourles.
In the evening, there are m opportunities to sell shares. The i-th of them allows to sell as many shares as you want, each at the price of bi bourles. You can’t sell more shares than you have.
It’s morning now and you possess r 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 n,m,r (1≤n≤30, 1≤m≤30, 1≤r≤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 n integers s1,s2,…,sn (1≤si≤1000); si indicates the opportunity to buy shares at the price of si bourles.
The following line contains m integers b1,b2,…,bm (1≤bi≤1000); bi indicates the opportunity to sell shares at the price of bi bourles.
Output
Output a single integer — the maximum number of bourles you can hold after the evening.
Examples
input
3 4 11
4 2 5
4 4 5 4
output
26
input
2 2 50
5 7
4 2
output
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 <ostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define ll long long
#define dd double
#define mes(x,y) memset(x,y,sizeof(y))
using namespace std;
ll gcd(ll a,ll b){//���Լ��
return b==0?a:gcd(b,a%b);
}
int main(){
int a,b,c;
while(cin>>a>>b>>c){
int x,y,max=0,min=1000;
for(int i=0;i<a;i++){
cin>>x;
if(x<min)min=x;
}
for(int i=0;i<b;i++){
cin>>y;
if(y>max)max=y;
}//先找早上股票的最小的价格,然后找晚上最贵的价格
if(max<=min){
cout<<c<<endl;continue;
}/如果早上最小的价格大于等于晚上最大的价格,那么是不赚的,不变就行了
else{
int sum=c%min+c/min*max;
cout<<sum<<endl;
}//如果早上最小的价格小于晚上最大的价格,那么赚得最大的钱为购买早上股票的余额加早上买的股票个数乘晚上最贵股票的价格
}
}