forked from RiviereGregory/CodinGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolutionStockExchangeLosses.txt
71 lines (58 loc) · 2.06 KB
/
SolutionStockExchangeLosses.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.*;
import java.io.*;
import java.math.*;
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
List<Integer> list = new ArrayList<>();
for(int i = 0 ; i < n ; i++){
list.add(in.nextInt());
}
Boolean conditionMonte = true;
Boolean conditionMonteDernier = false;
Integer maxValeur = list.get(0);
Integer minValeur = list.get(0);
Integer perteMax = maxValeur - minValeur;
for(int i = 0 ; i < n-1 ; i++){
if ((list.get(i+1) - list.get(i)) >= 0){
if((i+1) == (n-1)){
conditionMonteDernier = true;
}
//System.out.println("monte");
}else {
conditionMonte = false;
//System.out.println("descend");
}
if(list.get(i+1)>maxValeur){
if(perteMax < (maxValeur - minValeur)){
perteMax = maxValeur - minValeur;
//System.out.println("perte");
}
maxValeur = list.get(i+1);
minValeur = list.get(i+1);
//System.out.println( maxValeur);
}
if(list.get(i+1)<minValeur){
minValeur = list.get(i+1);
if(perteMax < (maxValeur - minValeur)){
perteMax = maxValeur - minValeur;
}
}
//System.out.println( maxValeur);
//System.out.println( minValeur);
//System.out.println( perteMax);
//System.out.println( "");
}
Integer perte = null;
if (conditionMonte){
perte = 0;
}else{
perte = -perteMax;
}
System.out.println(perte);
//System.out.println(Collections.max(list));
//System.out.println(Collections.min(list));
}
}