Submission #1147232

#TimeUsernameProblemLanguageResultExecution timeMemory
1147232paolaparedesCoin Collecting (JOI19_ho_t4)Java
0 / 100
77 ms13456 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(); long[][] coins = new long[2*N][2]; for (int i = 0; i < 2*N; i++) { coins[i][0] = sc.nextLong(); coins[i][1] = sc.nextLong(); } Arrays.sort(coins, (a, b) -> Long.compare(a[0], b[0])); long costX = 0, costY = 0; for (int i = 0; i < 2*N; i++) { long assignedCol = (i / 2) + 1; costX += Math.abs(coins[i][0] - assignedCol); } for (int i = 0; i < 2*N; i += 2) { long y1 = coins[i][1], y2 = coins[i+1][1]; long option1 = Math.abs(y1 - 1) + Math.abs(y2 - 2); long option2 = Math.abs(y1 - 2) + Math.abs(y2 - 1); costY += Math.min(option1, option2); } System.out.println(costX + costY); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...