AtCoder ABC 024 A&B&C AtCoder - 024
2019/05/27
Problem name correction
Fixed C problem code writing ʻint [] [] generation part
`
――For the time being, if you are eligible for a discount after adding up, you can discount
private void solveA() {
int[] first = IntStream.range(0, 4).map(i -> nextInt()).toArray();
int[] second = IntStream.range(0, 2).map(i -> nextInt()).toArray();
int child = second[0] * first[0];
int adult = second[1] * first[1];
int total = child + adult;
int sum = Arrays.stream(second).sum();
if (sum >= first[3]) {
total -= (sum * first[2]);
}
out.println(total);
}
--I will post the process as it is --Comment out the simplification
――I can't get an explanation of the solution. .. ..
private void solveB() {
int numN = nextInt();
int numT = nextInt();
int[] wk = IntStream.range(0, numN).map(i -> nextInt()).toArray();
long res = 0;
long preTime = 0;
for (int i = 0; i < wk.length; i++) {
long openTime = 0;
long currentTime = wk[i];
if (i == 0) {
preTime = currentTime;
openTime = numT;
} else {
if (preTime + numT > currentTime) {
openTime -= (preTime + numT) - currentTime;
openTime += numT;
preTime = currentTime;
} else {
preTime = currentTime;
openTime = numT;
}
}
// if (i != 0 && wk[i - 1] + numT > currentTime) {
// openTime -= (wk[i - 1] + numT) - currentTime;
// openTime += numT;
// } else {
// openTime = numT;
// }
res += openTime;
}
out.println(res);
}
――It is better to always go to the city where you can go the most on that day ――Determine the day you can start (the very first day within the movable range) ――Go to the city you can go to that day (whether you go to a big city or a small city depends on the tribe) ――The next day's start is the city you are currently in --Create a pattern to move from a city with a small number to a city with a large number and a pattern from a large number to a small number.
private void solveC() {
int n = nextInt();
int d = nextInt();
int k = nextInt();
int[][] aLR = Stream.generate(() -> new int[] { nextInt(), nextInt() }).limit(d).toArray(int[][]::new);
// int[][] aLR = IntStream.range(0, d).collect(() -> new int[d][2],
// (t, i) -> {
// t[i][0] = nextInt();
// t[i][1] = nextInt();
// }, (t, u) -> {
// Stream.concat(Arrays.stream(t), Arrays.stream(u));
// });
int[][] aST = Stream.generate(() -> new int[] { nextInt(), nextInt() }).limit(k).toArray(int[][]::new);
// int[][] aST = IntStream.range(0, k).collect(() -> new int[k][2],
// (t, i) -> {
// t[i][0] = nextInt();
// t[i][1] = nextInt();
// }, (t, u) -> {
// Stream.concat(Arrays.stream(t), Arrays.stream(u));
// });
for (int[] js : aST) {
long day = getDay(aLR, js[0], js[1]);
out.println(day);
}
}
private long getDay(int[][] aLR, int start, int end) {
int current = start;
if (start < end) {
for (int i = 0; i < aLR.length; i++) {
if (aLR[i][0] <= current && current <= aLR[i][1]) {
current = aLR[i][1];
}
if (current >= end) {
return i + 1;
}
}
} else {
for (int i = 0; i < aLR.length; i++) {
if (aLR[i][0] <= current && current <= aLR[i][1]) {
current = aLR[i][0];
}
if (current <= end) {
return i + 1;
}
}
}
return -1;
}
Recommended Posts