git reimport
This commit is contained in:
39
archive/2017.10/2017.10.15 - unsorted/B.java
Normal file
39
archive/2017.10/2017.10.15 - unsorted/B.java
Normal file
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user