Condition: Mr. Twister, banker and financier, has access to secret materials -a local cash currency rate on N days forward. As a person, everywhere trying to find benefits, Mr. Twister set himself a task -you need to choose a day when you need to buy this currency and when it needs to be sold to get the maximum profit.
Input format: The first line introduces the number N -the number of days to which the currency rate is known. In the second line there is n numbers -the cost of the currency in rubles to the appropriate day.
Output format: It is required to withdraw two numbers -a day when you need to buy a currency and a day when you need to sell it to get the maximum profit. Moreover, if you choose this a couple of days, you need to choose the one at which Mr. Twister will be able to sell currency from hand. If there are several such pairs, then you need to consider the same principle -the better the better. If you buy and sell currency in these days, it will be unprofitable or useless, then output -1.
Example: Input: five 1 2 1 5 3 Output: 3 4.
Enter: 3. 200 100 50. Conclusion:
Extinguits of my reasoning: I realized only that if the next number is the next number of the previous one, the stocks fall and need to withdraw -1. (0 Added to avoid index Out of Range)
n= int(input()) term= list(map(int, input().split())) term.append(0) if not any(term[i] < term[i + 1] for i in range(n)): print(-1)
Next, just fall into a stupor. The task seems familiar, perhaps its condition is popular at the Olympics. However, what algorithm? If you go throughout the list and iterator to track when the next number is smaller, and when there is more than the previous one, it is for a long time, in memory, and not the fact that logic will work. There was an option to search for the increasing indices of the maximum and minimum number to compare their position, but if the maximum is before the minimum, what's next? If someone came across an analogue, can you explain the principle, please?
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- dart - flutter: the instance member'stars' can't be accessed in an initializer error