Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Problem {
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int[] array = new int[n];
- for(int i=0; i<n; i++){
- array[i] = sc.nextInt();
- }
- System.out.println(minMoves(array, n));
- }
- public static int minMoves(int[] array, int n){
- int moves = 0;
- for(int i=1 ; i < n; i++){
- if(array[i] < array[i-1]){
- moves += (array[i-1] - array[i]);
- array[i] = array[i-1];
- }
- }
- return moves;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement