package PAT1008; import java.util.Scanner; public class Main { public static void main(String[] args) { int n; int preFloor, currFloor; int subtract; int sum; Scanner sc = new Scanner(System.in); n = sc.nextInt(); preFloor = 0; sum = 0; for(int i = 0; i < n; i++) { currFloor = sc.nextInt(); subtract = currFloor - preFloor; if(subtract > 0) { sum += 6*subtract; sum += 5; preFloor = currFloor; }else { sum += 4*Math.abs(subtract); sum += 5; preFloor = currFloor; } } System.out.println(sum); } }
PAT1008
最新推荐文章于 2020-06-25 21:42:41 发布