Google Code Jam 2011 Qualification Round 资格赛 Problem B. Investing at the Market 问题B.市场投资

 

Problem B. Investing at the Market

市场投资

 

Problem 问题

 

You have money M to invest and a forecast of a commodity price P for each month in the coming year. Of course you want profit! Figure out when to buy and sell in order to maximize your profit. You cannot buy a fraction of an item. You can assume that the price will be different each month. If two scenarios exist that result in the same profit, you should choose to buy at the lowest price per unit. You can only make a single purchase. If it is impossible to make a profit given the market trends, you should output IMPOSSIBLE.

 

你有这么多钱,M美元来投资,并且在下一年来临的时候每月一个商品价格的预测P美元。当然,你想要获取利润!指出什么时候买卖来获取最大的利润。你不能买一个条目的部分。你可以假设每月的价格不一样。如果存在两种情况都能获得同样的利润,你应该选择在每个单元最低价的时候购买。你只能 买一次。如果根据市场趋势不能获得利润,则输出IMPOSSIBLE.

 

Input 输入

 

The first line of input gives the number of cases, N.

N test cases follow. For each test case there will be:

第一行输入给出例子数量N

下面跟着N个例子。对于每一个测试用例将会有:

 

One line containing the amount of money M that you have to invest.

一行,包含你用于投资的钱M

One line containing a space separated list of 12 integers P indicating the price at the beginning of each month.

一行,包含空格分隔的列表,十二个整数P,表示每月开始的价格。

 

Output 输出

 

For each test case, output one line containing "Case #x: " followed by either the word "IMPOSSIBLE" or three space separated integers:

对于每个用例,输出一行包含Case #x: 跟着一个词IMPOSSIBL或者三个空格分隔的整数:

 

The index B of the month when you should buy the goods. An integer between 1 and 11 (inclusive).

索引B,你应该买商品的月。一个整数,在1到11之间,闭区间

The index of the month when you should sell the goods. An integer between (B + 1) and 12 (inclusive).

月的索引,当你要卖出商品的时候。一个整数在B+1到12之间,闭区间

The amount of profit that your investment plan will return.

投资计划返回的利润总数

 

Limits 限制

 

100 ≤ M ≤ 500

1 ≤ P ≤ 250

 

Small dataset

 

N ≤ 10

 

Large dataset

 

N ≤ 200

 

Sample

 

Input 

3

100

1 2 3 4 5 6 7 8 9 10 11 12

100

52 50 25 100 61 63 70 51 71 55 10 5

100

200 150 250 132 125 110 210 220 180 176 108 113

 

 

Output 

Case #1: 1 12 1100

Case #2: 3 4 300

Case #3: IMPOSSIBLE

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值