AtCoder ABC 031 A&B&C AtCoder - 031
private void solveA() {
int a = nextInt();
int d = nextInt();
int res = 0;
if (a > d) {
res = a * (d + 1);
} else {
res = d * (a + 1);
}
out.println(res);
}
private void solveB() {
int numL = nextInt();
int numH = nextInt();
int numN = nextInt();
int[] wk = IntStream.range(0, numN).map(i -> nextInt()).toArray();
for (int i : wk) {
if (i < numL) {
out.println(numL - i);
} else if (numH < i) {
out.println(-1);
} else {
out.println(0);
}
}
}
--Brute force ββIt took more than an hour to make the question sentence meaningful due to reading comprehension, but ... ββI implemented it according to the following policy, so is it okay?
I'm not confident that I can get the same answer again. .. ..
private void solveC() {
int numN = nextInt();
int[] wk = IntStream.range(0, numN).map(i -> nextInt()).toArray();
int res = Integer.MIN_VALUE;
/*
*Brute force where Takahashi chooses
*Aoki's hand is decided depending on the place Takahashi chose
*Should be. .. ..
* i=Takahashi's selection place
*/
for (int i = 0; i < numN; i++) {
/*
* Integer.MIN_When I set it to VALUE, the value was looped to the MAX side, so ...
*Points of Takahashi and Aoki when Takahashi selects this position
*/
int aokiPoint = -1000000;
int takahashiPoint = 0;
/*
*With the selected position of Takahashi fixed
*Find Aoki's selection location
*This selection place is where Aoki's point is the maximum
* i==When it is j, Takahashi and his hand are covered, so he cannot select it.
*The point of Takahashi is where Aoki's point is the largest.
*
*/
for (int j = 0; j < numN; j++) {
if (i == j) {
continue;
}
int innerAoki = -100000;
int innerTakahashi = 0;
/*
*The smaller one starts at the selected position of either Aoki or Takahashi
*The larger selection position of either Aoki or Takahashi ends
*Since both ends are included, the end is<=
*/
int cnt = 1;
for (int k = Integer.min(i, j); k <= Integer.max(i, j); k++) {
/*
*Odd is Takahashi's point
*Even numbers are Aoki's points
*/
if ((cnt & 1) == 1) {
innerTakahashi += wk[k];
} else {
innerAoki += wk[k];
}
cnt++;
}
/*
*Aoki's point when this position is selected is
*Whether it is larger than Aoki's points so far
*If it is large, Takahashi's point is confirmed with this
*/
if (innerAoki > aokiPoint) {
//If it is larger than Aoki's point so far, replace it
aokiPoint = innerAoki;
//Aoki's points are bigger than before, so Takahashi's points are also replaced
takahashiPoint = innerTakahashi;
}
}
/*
*Whether or not this Takahashi's choice is greater than the previous points
*/
res = Integer.max(res, takahashiPoint);
}
out.println(res);
}
Recommended Posts