private static int maxProfit(int[] prices){
int maxMoney=0;
int count=0;
for(int i=0;i<prices.length-1;i++){
if(prices[i]<=prices[i+1]){
count++;
}else{
maxMoney+=prices[i]-prices[i-count];
count=0;
}
}
if(count>0){
maxMoney+=prices[prices.length-1]-prices[prices.length-1-count];
}
return maxMoney;
}