QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 33

#14009. 在市场投资

统计

你有资金 $M$ 用于投资,以及未来一年中每个月某种商品的价格预测 $P$。当然,你想要获得利润!请找出何时买入和卖出以最大化你的利润。你不能购买非整数个商品。你可以假设每个月的价格都是不同的。如果存在两种能获得相同利润的方案,你应该选择以最低的单价买入。你只能进行一次买入和卖出。如果根据市场趋势无法获得利润,你应该输出 IMPOSSIBLE

输入格式

输入的第一行给出测试用例的数量 $N$。

接下来是 $N$ 个测试用例。对于每个测试用例:

  • 一行,包含你用于投资的资金量 $M$。
  • 一行,包含 12 个空格分隔的整数 $P$,表示每个月初的价格。

输出格式

对于每个测试用例,输出一行,包含 "Case #$x$: ",后跟单词 "IMPOSSIBLE" 或三个空格分隔的整数:

  • 你应该买入商品的月份索引 $B$。一个介于 1 和 11 之间(含)的整数。
  • 你应该卖出商品的月份索引。一个介于 ($B + 1$) 和 12 之间(含)的整数。
  • 你的投资计划将回报的利润额。

数据范围

  • $100 \le M \le 500$
  • $1 \le P \le 250$

小数据规模(10 分)

  • $N \le 10$

大数据规模(10 分)

  • $N \le 200$

样例

输入 1

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

输出 1

Case #1: 1 12 1100
Case #2: 3 4 300
Case #3: IMPOSSIBLE

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.