Last active
October 8, 2017 00:04
-
-
Save mizushou/658d08747cb765889a98549bf876f88e to your computer and use it in GitHub Desktop.
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.io.BufferedReader; | |
import java.io.InputStreamReader; | |
public class Main { | |
public static void main(String[] args) throws Exception { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String l1 = br.readLine(); | |
String l2 = br.readLine(); | |
int n = Integer.parseInt(l1); | |
int k = Integer.parseInt(l2); | |
String l3 = br.readLine(); | |
String[] l3array = l3.split(" "); | |
int sum = 0; | |
for(int i = 0; i < l3array.length; i++) { | |
int la = Math.abs(Integer.parseInt(l3array[i])); | |
int lb = Math.abs(Integer.parseInt(l3array[i]) - k); | |
if(la - lb > 0) { | |
sum += lb * 2 ; | |
} else { | |
sum += la * 2; | |
} | |
} | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AtCoder Beginners Contest 74