当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3172:Scales

题目描述
Farmer John has a balance for weighing the cows. He also has a set of N (1 <= N <= 1000) weights with known masses (all of which fit in 31 bits) for use on one side of the balance. He places a cow on one side of the balance and then adds weights to the other side until they balance. (FJ cannot put weights on the same side of the balance as the cow, because cows tend to kick weights in his face whenever they can.) The balance has a maximum mass rating and will break if FJ uses more than a certain total mass C (1 <= C < 2^30) on one side.

The weights have the curious property that when lined up from smallest to biggest, each weight (from the third one on) has at least as much mass as the previous two combined.

FJ wants to determine the maximum mass that he can use his weights to measure exactly. Since the total mass must be no larger than C, he might not be able to put all the weights onto the scale.

Write a program that, given a list of weights and the maximum mass the balance can take, will determine the maximum legal mass that he can weigh exactly.
输入解释
Line 1: Two space-separated positive integers, N and C.

Lines 2..N+1: Each line contains a single positive integer that is the mass of one weight. The masses are guaranteed to be in non-decreasing order.
输出解释
Line 1: A single integer that is the largest mass that can be accurately and safely measured.
输入样例
3 15
1
10
20
输出样例
11
提示
Explanation of the sample:

FJ has 3 weights, with masses of 1, 10, and 20 units. He can put at most 15 units on one side of his balance.

The 1 and 10 weights are used to measure 11. Any greater weight that can be formed from the weights will break the balance.

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3172

最后修改于 2020-10-29T06:54:49+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536