您的位置:首页 > 其它

Gym 100703M It's complicated 水题

2015-07-27 20:05 357 查看
M. It's complicated

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Dragon was drinking tea on a balcony and admiring a very beautiful sunset. Two outgoing silhouettes were still descrying in the rays of a setting sun. Of course, Princess promised to visit Dragon sometime, but what could be a reason for her to come back in
the Castles Valley?..

Dragon decided to cook biscuits according to a recipe that was told him by Princess. So he needs to check if he has sufficient quantity of ingredients for it. Of course, he has a few of ginger, cinnamon, cloves and cardamon... But, comparing to making tea,
he needs some more ingredients to bake biscuits.

Dragon revised all his ingredients, and knew how many units of each ingredient he had.

It was written in the recipe how many units of each ingredient are required to bake a biscuit. Certainly, Dragon wanted to bake an integer number of biscuits.

Dragon realized that he will expend some ingredients completely, while some other ingredients will remain. He believed he must purchase some extra ingredients, so that all ingredients will be completely expended after baking some number of biscuits.

Dragon knew the cost for a unit of each ingredient. Your task is to figure out minimum amount of money which is needed to spend to fulfil the condition above.

Input

The first line contains integer n (1 ≤ n ≤ 10) —
the number of ingredients.

The second line contains n integers q1, q2, ..., qn (1 ≤ qj ≤ 100,  j = 1, 2, ..., n), qj —
the number of units of jth ingredient, which Dragon has.

The third line contains n integers c1, c2, ..., cn (1 ≤ cj ≤ 10,  j = 1, 2, ..., n), cj —
the number of units of jth ingredient which it needs for cooking a biscuit.

The fourth line contains n integers p1, p2, ..., pn (1 ≤ pj ≤ 100,  j = 1, 2, ..., n), pj —
cost of a unit of jth ingredient.

Output

Print the only integer — minimum amount of money to spend.

Sample test(s)

input
3
15 8 10
2 3 5
12 1 4


output
148


题目链接:http://codeforces.com/gym/100703/problem/M

AC代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MAXN 110 //1e6
#define y1 y234
int n;
int q[MAXN], c[MAXN], p[MAXN];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &q[i]);
}
for(int i = 1; i <= n; i++) {
scanf("%d", &c[i]);
}
for(int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
}
int maxx = 0;
for(int i = 1; i <= n; i++) {
maxx = max(maxx, (q[i] + c[i] - 1) / c[i]);
}
int ans = 0;
for(int i = 1; i <= n; i++) {
ans += p[i] * (maxx * c[i] - q[i]);
}
printf("%d\n", ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: