Submission #70982865
Source Code Expand
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
long X = Long.parseLong(st.nextToken());
long Y = Long.parseLong(st.nextToken());
long[] A = new long[N];
st = new StringTokenizer(br.readLine());
long minA = Long.MAX_VALUE;
long maxA = Long.MIN_VALUE;
long D = Y - X;
long K = -1;
boolean possible = true;
for (int i = 0; i < N; i++) {
A[i] = Long.parseLong(st.nextToken());
minA = Math.min(minA, A[i]);
maxA = Math.max(maxA, A[i]);
long currentK = (A[i] * X) % D;
if (K == -1) {
K = currentK;
} else if (K != currentK) {
possible = false;
}
}
if (!possible) {
out.println(-1);
out.flush();
return;
}
long W_lower_bound = maxA * X;
long W_upper_bound = minA * Y;
if (W_lower_bound > W_upper_bound) {
out.println(-1);
out.flush();
return;
}
long W_max = W_upper_bound;
long totalLargeCandies = 0;
for (int i = 0; i < N; i++) {
long li = (W_max - A[i] * X) / D;
totalLargeCandies += li;
}
out.println(totalLargeCandies);
out.flush();
br.close();
out.close();
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Candy Tribulation |
| User | addy |
| Language | Java24 (OpenJDK 24.0.2) |
| Score | 350 |
| Code Size | 1898 Byte |
| Status | AC |
| Exec Time | 182 ms |
| Memory | 62696 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.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, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 41 ms | 38296 KiB |
| 00-sample-02.txt | AC | 39 ms | 38480 KiB |
| 00-sample-03.txt | AC | 38 ms | 38092 KiB |
| 01-01.txt | AC | 152 ms | 50700 KiB |
| 01-02.txt | AC | 99 ms | 43884 KiB |
| 01-03.txt | AC | 140 ms | 53992 KiB |
| 01-04.txt | AC | 154 ms | 54672 KiB |
| 01-05.txt | AC | 142 ms | 54464 KiB |
| 01-06.txt | AC | 175 ms | 62696 KiB |
| 01-07.txt | AC | 168 ms | 61372 KiB |
| 01-08.txt | AC | 182 ms | 62328 KiB |
| 01-09.txt | AC | 170 ms | 62112 KiB |
| 01-10.txt | AC | 175 ms | 61412 KiB |
| 01-11.txt | AC | 163 ms | 61096 KiB |
| 01-12.txt | AC | 174 ms | 62016 KiB |
| 01-13.txt | AC | 158 ms | 56860 KiB |
| 01-14.txt | AC | 178 ms | 61292 KiB |
| 01-15.txt | AC | 173 ms | 61188 KiB |
| 01-16.txt | AC | 161 ms | 61872 KiB |
| 01-17.txt | AC | 179 ms | 61532 KiB |
| 01-18.txt | AC | 168 ms | 61244 KiB |
| 01-19.txt | AC | 172 ms | 62348 KiB |
| 01-20.txt | AC | 179 ms | 62600 KiB |
| 01-21.txt | AC | 169 ms | 61784 KiB |
| 01-22.txt | AC | 167 ms | 62004 KiB |
| 01-23.txt | AC | 167 ms | 62660 KiB |
| 01-24.txt | AC | 167 ms | 61776 KiB |
| 01-25.txt | AC | 155 ms | 57852 KiB |
| 01-26.txt | AC | 144 ms | 52964 KiB |
| 01-27.txt | AC | 170 ms | 61404 KiB |
| 01-28.txt | AC | 158 ms | 56136 KiB |
| 01-29.txt | AC | 176 ms | 61324 KiB |
| 01-30.txt | AC | 176 ms | 62400 KiB |
| 01-31.txt | AC | 152 ms | 54944 KiB |
| 01-32.txt | AC | 173 ms | 62080 KiB |
| 01-33.txt | AC | 168 ms | 62684 KiB |
| 01-34.txt | AC | 158 ms | 57036 KiB |
| 01-35.txt | AC | 171 ms | 61824 KiB |
| 01-36.txt | AC | 169 ms | 62320 KiB |
| 01-37.txt | AC | 143 ms | 54232 KiB |
| 01-38.txt | AC | 173 ms | 62444 KiB |
| 01-39.txt | AC | 168 ms | 62272 KiB |
| 01-40.txt | AC | 157 ms | 57136 KiB |
| 01-41.txt | AC | 161 ms | 56456 KiB |
| 01-42.txt | AC | 154 ms | 53792 KiB |
| 01-43.txt | AC | 167 ms | 61964 KiB |