Submission #74304737
Source Code Expand
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputReader reader = new InputReader(System.in);
PrintWriter writer = new PrintWriter(System.out, false);
int N = reader.nextInt();
int K = reader.nextInt();
int[] A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = reader.nextInt() % K;
}
Arrays.sort(A);
int max = 0;
for (int i = 0; i + 1 < N; i++) {
max = Math.max(max, A[i + 1] - A[i]);
}
max = Math.max(max, A[0] + K - A[N - 1]);
writer.println(K - max);
writer.close();
System.exit(0);
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
String str = "";
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Minimize Range |
| User | UttamS |
| Language | Java24 (OpenJDK 24.0.2) |
| Score | 400 |
| Code Size | 1928 Byte |
| Status | AC |
| Exec Time | 282 ms |
| Memory | 63028 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_01.txt, 00_sample_02.txt, 01_01.txt, 01_02.txt, 01_03.txt, 01_04.txt, 01_05.txt, 01_06.txt, 01_07.txt, 01_08.txt, 01_09.txt, 01_10.txt, 01_11.txt, 01_12.txt, 01_13.txt, 01_14.txt, 01_15.txt, 01_16.txt, 01_17.txt, 01_18.txt, 01_19.txt, 01_20.txt, 02_01.txt, 02_02.txt, 02_03.txt, 02_04.txt, 02_05.txt, 02_06.txt, 02_07.txt, 02_08.txt, 02_09.txt, 02_10.txt, 02_11.txt, 02_12.txt, 03_01.txt, 03_02.txt, 03_03.txt, 03_04.txt, 03_05.txt, 03_06.txt, 03_07.txt, 03_08.txt, 03_09.txt, 03_10.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 59 ms | 39352 KiB |
| 00_sample_02.txt | AC | 69 ms | 39428 KiB |
| 01_01.txt | AC | 229 ms | 52292 KiB |
| 01_02.txt | AC | 226 ms | 54788 KiB |
| 01_03.txt | AC | 262 ms | 58436 KiB |
| 01_04.txt | AC | 215 ms | 51632 KiB |
| 01_05.txt | AC | 199 ms | 49748 KiB |
| 01_06.txt | AC | 167 ms | 47496 KiB |
| 01_07.txt | AC | 137 ms | 44644 KiB |
| 01_08.txt | AC | 158 ms | 46240 KiB |
| 01_09.txt | AC | 244 ms | 56428 KiB |
| 01_10.txt | AC | 152 ms | 45448 KiB |
| 01_11.txt | AC | 194 ms | 49228 KiB |
| 01_12.txt | AC | 228 ms | 51876 KiB |
| 01_13.txt | AC | 170 ms | 46888 KiB |
| 01_14.txt | AC | 212 ms | 50456 KiB |
| 01_15.txt | AC | 181 ms | 47944 KiB |
| 01_16.txt | AC | 80 ms | 40836 KiB |
| 01_17.txt | AC | 239 ms | 57500 KiB |
| 01_18.txt | AC | 234 ms | 55540 KiB |
| 01_19.txt | AC | 255 ms | 61300 KiB |
| 01_20.txt | AC | 240 ms | 56576 KiB |
| 02_01.txt | AC | 58 ms | 39268 KiB |
| 02_02.txt | AC | 57 ms | 39148 KiB |
| 02_03.txt | AC | 59 ms | 39564 KiB |
| 02_04.txt | AC | 61 ms | 39268 KiB |
| 02_05.txt | AC | 60 ms | 39280 KiB |
| 02_06.txt | AC | 59 ms | 39232 KiB |
| 02_07.txt | AC | 168 ms | 54220 KiB |
| 02_08.txt | AC | 206 ms | 61820 KiB |
| 02_09.txt | AC | 207 ms | 61144 KiB |
| 02_10.txt | AC | 174 ms | 54320 KiB |
| 02_11.txt | AC | 210 ms | 62656 KiB |
| 02_12.txt | AC | 268 ms | 61700 KiB |
| 03_01.txt | AC | 255 ms | 61352 KiB |
| 03_02.txt | AC | 282 ms | 61364 KiB |
| 03_03.txt | AC | 268 ms | 63028 KiB |
| 03_04.txt | AC | 261 ms | 61756 KiB |
| 03_05.txt | AC | 269 ms | 62028 KiB |
| 03_06.txt | AC | 262 ms | 62904 KiB |
| 03_07.txt | AC | 269 ms | 61212 KiB |
| 03_08.txt | AC | 272 ms | 61336 KiB |
| 03_09.txt | AC | 270 ms | 63008 KiB |
| 03_10.txt | AC | 265 ms | 62800 KiB |