40 lines
778 B
Java
40 lines
778 B
Java
package chelper;
|
|
|
|
import io.InputReader;
|
|
import io.OutputWriter;
|
|
import misc.SimpleSavingChelperSolution;
|
|
|
|
|
|
public class B extends SimpleSavingChelperSolution {
|
|
|
|
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
|
wrapSolve(testNumber, in, out);
|
|
}
|
|
|
|
@Override
|
|
public void solve(int testNumber) {
|
|
int n = in.nextInt();
|
|
int k = in.nextInt();
|
|
|
|
int[] a = in.nextIntArray(n);
|
|
|
|
int globalMin = a[0];
|
|
int globalMax = a[0];
|
|
|
|
for (int i : a) {
|
|
globalMax = Math.max(globalMax, i);
|
|
globalMin = Math.min(globalMin, i);
|
|
}
|
|
|
|
int twoMax = Math.max(a[0], a[n - 1]);
|
|
|
|
if (k == 1) {
|
|
out.println(globalMin);
|
|
} else if (k == 2) {
|
|
out.println(twoMax);
|
|
} else {
|
|
out.println(globalMax);
|
|
}
|
|
}
|
|
}
|