Created
August 30, 2013 04:54
-
-
Save anonymous/6386439 to your computer and use it in GitHub Desktop.
Pat#1008
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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