18 new game 4. DEAL

Title description: After Double Eleven, syx found that he was about to eat Soiled. But witty he decided to manage money. He predicted the bitcoin market for the next n days and found that there will be ups and downs, and down and ups. As long as the money in your hand experiences ups and downs in the wave of Bitcoin, low-priced income, high-priced selling, you can easily cut other people’s leeks and become rich. In order to reduce the risk, he decided to keep no more than 1 Bitcoin in his hand at any time, and he wanted to minimize the number of transactions taking place while making the most profit. Now give the bitcoin market for n days, that is, the value of 1 bitcoin per day. Please find out how much syx can profit at most after n days? What is the minimum number of transactions in the case of maximum profit? We assume that syx has unlimited money at the beginning, because even if he borrows money, he has to make a wave.

input: first There is an integer T in the row, which means there are T groups of data in total. 0

For the first row of each set of data, there is an integer n, which means that the market has been predicted for n days (1 <= n <= 100000)

For the second row of each set of data, there are n integers ai , respectively represent the market quotation on the i-th day. (0 <= ai <= 1010)

output

For each set of samples, output a line of two integers separated by spaces to indicate the maximum gain Lihe minimum number of transactions

Sample input

2 5 9 10 7 6 8 3 3 2 1

Sample output

3 4 0 0



Code
< strong>#includeint main() {int T; long long b [6],c[6]; scanf("%d",&T); for(int j=0; ja[i]) {money=money+(a[i+1]-a[i ]); s++; //Calculate the price difference, else {s=0; //Introduce the variable s as the criterion, no matter how many consecutive transactions, in order to count the minimum number of times, the final number of times will be 2 when the latter If the former is small, there will be a loss, s is cleared if(s==1) x=x+2; b[j]=money; c[j]=x;} for(int i=0; i

For the first row of each set of data, there is an integer n, indicating that the market has been forecasted for n days (1 <= n <= 100000)

For the second row of each group of data, there are n integers ai, representing the i-th day Quotes. (0 <= ai <= 1010)

For each set of samples, output a line of two integers separated by spaces to indicate the maximum profit and minimum number of transactions

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 332 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.