Submission #1145528

#TimeUsernameProblemLanguageResultExecution timeMemory
1145528machaca_rodrigoCoin Collecting (JOI19_ho_t4)Java
0 / 100
84 ms13208 KiB
import java.util.*; public class joi2019_ho_t4 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int total = 2 * N; long[] xs = new long[total]; long[] ys = new long[total]; for (int i = 0; i < total; i++) { xs[i] = sc.nextLong(); ys[i] = sc.nextLong(); } Arrays.sort(xs); long costX = 0; for (int i = 0; i < total; i++) { long target = (i / 2) + 1; costX += Math.abs(xs[i] - target); } long baseY = 0; int countRow1 = 0; for (int i = 0; i < total; i++) { if (ys[i] <= 1) { baseY += (2 - ys[i]); countRow1++; } else { baseY += (ys[i] - 2); } } long extra = (countRow1 >= N) ? -N : (N - 2L * countRow1); long costY = baseY + extra; System.out.println(costX + costY); sc.close(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...