Pro.ID22128 TitleInvestment Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22128 AC0 Submit0 Ratio- 时间&空间限制描述Stock market analyzing is very important for investment. A good analysis may earn you a lot of money, or at least minimize your loss. Now you are asked to carry out such an important task. Please write a program to select out 2 most beneficial stocks. There are N kinds of stocks in the market and they are simply represented by integers from 1 to N. Each of the N stocks has an initial price which is changing frequently. Benefits are calculated as follows: if a stock has no previous price, then its benefit is 0, otherwise the benefit is its current price subtracts its previous price. For stocks with the same benefits, select the one with least id first. 输入There are multiple test cases. The first line of each case is the number N ( 2 <= N <= 100000). Then followed by N lines and each line has an integer number Pi ( 1 <= Pi <= 10000 ) which specify the initial prices of the stocks from 1 to N. Then followed by k ( 0 <= k <= 100000 ) lines and each line may be either two integers-id and Pid which tells that the idth stock price changed to Pid, or an instruction "Report" (without quotes). After these k lines there will be a line containing only "EndOfCurrentCase" (without quotes), which indicate the end of current case. And after all cases there will be a line containing only "EndOfInput" (without quotes), which indicate the end of input. 输出Description Stock market analyzing is very important for investment. A good analysis may earn you a lot of money, or at least minimize your loss. Now you are asked to carry out such an important task. Please write a program to select out 2 most beneficial stocks. There are N kinds of stocks in the market and they are simply represented by integers from 1 to N. Each of the N stocks has an initial price which is changing frequently. Benefits are calculated as follows: if a stock has no previous price, then its benefit is 0, otherwise the benefit is its current price subtracts its previous price. For stocks with the same benefits, select the one with least id first. Input There are multiple test cases. The first line of each case is the number N ( 2 <= N <= 100000). Then followed by N lines and each line has an integer number Pi ( 1 <= Pi <= 10000 ) which specify the initial prices of the stocks from 1 to N. Then followed by k ( 0 <= k <= 100000 ) lines and each line may be either two integers-id and Pid which tells that the idth stock price changed to Pid, or an instruction "Report" (without quotes). After these k lines there will be a line containing only "EndOfCurrentCase" (without quotes), which indicate the end of current case. And after all cases there will be a line containing only "EndOfInput" (without quotes), which indicate the end of input. Output For each case, output the case number (see the sample output) first, then followed by several lines, each line contains 2 integers (separated by a blank) specifying the top 2 stock ids corresponding to the "Report" instruction. No redundant spaces are needed. Sample Input 4
10
20
30
40
1
100
2 90
3 80
4 70
Report
Report
2 60
Report
EndOfCurrentCase
3
1
1
1
2 10
3 20
Report
EndOfCurrentCase
EndOfInput Sample Output Case 1:
1 2
1 2
1 3
Case 2:
3 2 Source 样例输入4
10
20
30
40
1
100
2 90
3 80
4 70
Report
Report
2 60
Report
EndOfCurrentCase
3
1
1
1
2 10
3 20
Report
EndOfCurrentCase
EndOfInput 样例输出Case 1:
1 2
1 2
1 3
Case 2:
3 2 作者 |