Skip to content

Instantly share code, notes, and snippets.

Created August 30, 2013 04:54
Show Gist options
  • Save anonymous/6386439 to your computer and use it in GitHub Desktop.
Save anonymous/6386439 to your computer and use it in GitHub Desktop.
Pat#1008
import java.util.Scanner;
public class Main {
static int sumTime(int[] arr, int upcost, int downcost, int stopcost){
int up=arr[0], down=0, stop=arr.length;
for(int i=1; i<arr.length; i++){
int diff = arr[i] -arr[i-1];
if(diff>0)
up += diff;
else
down -= diff;
}
return up*upcost + down*downcost + stop*stopcost;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] arr = new int[N];
for(int i=0; i<N; i++)
arr[i] = sc.nextInt();
System.out.println(sumTime(arr, 6,4,5));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment