time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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
inputCopy
3 4 11
4 2 5
4 4 5 4
outputCopy
26
inputCopy
2 2 50
5 7
4 2
outputCopy
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<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<vector>
#define ll long long
#define dd double
using namespace std;
int main() {
ll n, m, k;
//输入三个数分别代表早晨的数量,晚上的数量,你的钱
cin >> n >> m >> k;
ll a[1005];
ll b[1005];
for (ll i = 0; i < n; i++) {
cin >> a[i];//早晨的数量
}
sort(a, a + n);//从小到大排序
for (ll i = 0; i < m; i++) {
cin >> b[i];//晚上的数量
}
sort(b, b + m);//从小到达排序
if (a[0] > b[m - 1]) {//如果早晨买入的最低价高于晚上卖出的最高价,就不买了
cout << k << endl;
}
else {
ll t = k % a[0];//否则,买早上的最低价,用t存储剩下的钱
ll t1 = k / a[0];
t1 = t1 * b[m - 1] + t;//买的数量按晚上的最高价卖出去,再加上早上剩下的钱
cout << t1 << endl;//就是最后的结果
}
}