Maximum Profit Aizu - ALDS1_1_D
Maximum Profit
You can obtain profits from foreign exchange margin transactions.
你可以從外匯保證金交易中獲得利潤。
For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen.
例如,如果你以每美元100日元的匯率購買1000美元,然后以每美元108日元的匯率出售,你可以得到(108-100)×1000=8000日元。
Write a program which reads values of a currency Rt at a certain time t (t=0,1,2,…n?1), and reports the maximum value of Rj?Ri where j>i .
編寫一個程序,在特定時間t(t=0,1,2,…n?1)讀取貨幣rt的值,并報告rj?ri的最大值,其中j>i。
Input
The first line contains an integer n. In the following n lines, Rt (t=0,1,2,…n?1) are given in order.
第一行包含一個整數n。在下面的n行中,rt(t=0,1,2,…n?1)按順序給出。
Output
Print the maximum value in a line.
打印一行中的最大值。
Constraints
2≤n≤200,000
1≤Rt≤109
Sample Input 1
6
5
3
1
3
4
3
Sample Output 1
3
Sample Input 2
3
4
3
2
Sample Output 2
-1
code
/*^....0^ .1 ^1^.. 011.^ 1.0^ 1 ^ ^0.11 ^ ^..^0. ^ 0^.0 1 .^.1 ^0 .........001^.1 1. .111100....01^00 ^ 11^ ^1. .1^1.^ ^0 0^.^ ^0..1.1 1..^1 .0 ^ ^^ 00. ^^0.^1 ^ 0 ^^110.^0. 0 ^ ^^^10.01^^ 010^ 1 1 ^^^1110.10001 10 0 ^ 1.1 ^^^11111100^ 10 . 01 ^^ ^^ ^^^1111^1.^ ^^^10 10^ 0^ ^^111^^^0.1^ 1....^11 0 ^^11^^^ 0.. ....1^ ^ ^1. 0^ ^11^^^ ^ 1 111^ ^ 0.10 00 11 ^^^^^ 1 0 1.0^ ^0 ^0 ^^^^ 0 0.0^ 1.0 .^ ^^^^ 1 1 .0^.^ ^^ 0^ ^1 ^^^^ 0. ^.11 ^ 11 1. ^^^ ^ ^ ..^^..^ ^1 ^.^ ^^^ .0 ^.00..^ ^0 01 ^^^ .. 0..^1 .. .1 ^.^ ^^^ 1 ^ ^0001^ 1. 00 0. ^^^ ^.0 ^.1. 0^. ^.^ ^.^ ^^^ ..0.01 .^^. .^ 1001 ^^ ^^^ . 1^. ^ ^. 11 0. 1 ^ ^^ 0.0 ^. 0 ^0 1 ^^^ 0.0.^ 1. 0^ 0 .1 ^^^ ...1 1. 00 . .1 ^^^ ..1 1. ^. 0 .^ ^^ ..0. 1. .^ . 0 ..1 1. 01 . . ^ 0^.^ 00 ^0 1. ^ 1 1.0 00 . ^^^^^^ ..^ 00 01 ..1. 00 10 1 ^^.1 00 ^. ^^^ .1.. 00 .1 1..01 ..1.1 00 1. ..^ 10^ 1^ 00 ^.1 0 1 1.1 00 00 ^ 1 ^. 00 ^.^ 10^ ^^1.1 00 00 10^..^ 1. ^. 1.0 1 ^. 00 00 .^^ ^. ^ 1 00 ^0000^ 0 011 0 ^. 00.0^ ^1.0.1 1.00.1 11. 1 0 1^^0.01 ^^^ 01.^ ^ 1 1^^ ^.^1 1 0... 1 ^1 1^ ^ .01 ^ 1.. 1.1 ^0.0^ 0 1..01^^100000..0^1 1 ^ 1 ^^1111^ ^^0 ^ ^ 1 1000^.1 ^.^ . 00.. 1.1 0. 01. . 1. .^1. 1 1. ^0^ . ^.1 00 01^.0 001. .^*/ // Virtual_Judge —— Maximum Profit Aizu - ALDS1_1_D.cpp created by VB_KoKing on 2019,04,24,19. /* Procedural objectives:Procedural thinking:在下標自增的過程中,將現階段rt最小值保存下來。Functions required by the program:Variables required by the program:*/ /* My dear Max said: "I like you, So the first bunch of sunshine I saw in the morning is you, The first hurricane that passed through your ear is you, The first star you see is also you. The world I see is all your shadow."FIGHTING FOR OUR FUTURE!!! */ #include <set> #include <map> #include <list> #include <deque> #include <stack> #include <queue> #include <cmath> #include <cstdio> #include <string> #include <vector> #include <cctype> #include <sstream> #include <complex> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <functional> using namespace std; int main() {int n;cin>>n;int rt[200000];memset(rt,0, sizeof(rt));for (int i = 0; i < n; ++i) {cin >> rt[i];}int maxv=-2000000000,minv=rt[0];for (int i = 1; i < n; i++) { maxv=max(maxv,rt[i]-minv); //更新最大值minv=min(minv,rt[i]); //暫存現階段的最小值}cout<<maxv<<endl;return 0; }總結
以上是生活随笔為你收集整理的Maximum Profit Aizu - ALDS1_1_D的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Codeforces Round #55
- 下一篇: 1131:基因相关性