Skip to content

Instantly share code, notes, and snippets.

@mizushou
Last active October 8, 2017 00:04
Show Gist options
  • Save mizushou/658d08747cb765889a98549bf876f88e to your computer and use it in GitHub Desktop.
Save mizushou/658d08747cb765889a98549bf876f88e to your computer and use it in GitHub Desktop.
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);
}
}
@mizushou
Copy link
Author

AtCoder Beginners Contest 74

  • B - Collecting Balls (Easy Version)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment