Dummies four time limit: 1000 MS | memory limit: 65535 kb difficulty: 3
-
Description
-
These days, dummies have been studying stocks. After research, they finally found that the stock laws of XXX company. what's even better is that dummies work out the company's stock price every day to prevent others from discovering its secrets. He decided to buy the company's stock at most once, and now the dumb has listed the stock price. (This is no longer an idiot's problem. He has solved it ). I just want to make it difficult for you. From the stock price list, Can you calculate the maximum amount of money a dumb can earn per share?
-
Input
-
The first line is N, indicating N days (less than 100000)
The second row provides the price per share for N days.
-
Output
-
Maximum earnings per share
-
Sample Input
-
4947 267 359 7717669 735 322 794 397 565 181
-
Sample output
-
504472
-
# Include <stdio. h> int main () {int day; while (scanf ("% d", & day )! = EOF) {int max = 0, S, sum = 0, x, y; scanf ("% d", & X); Day --; while (day --) {scanf ("% d", & Y); s = Y-X; // sum of the difference between the last item and the previous one <0? Sum = s: Sum + = s; // when sum is less than 0, the value of S is assigned to sum. Otherwise, the sum will continue! Max <sum? Max = sum: Sum = sum; // compare and assign the values of limit to max X = y; // prepare for the next loop} printf ("% d \ n ", max); // The maximum amount of money transferred per share.} return 0 ;}
Nyoj 739 stupid question 4