Created
March 12, 2018 21:36
-
-
Save fredbr/0a5fc54d22874c5a3bda9cdd120400b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
const int maxn = 100010; | |
const int inf = 0x3f3f3f3f; | |
int v[maxn]; | |
int main() | |
{ | |
ios_base::sync_with_stdio(false); | |
cin.tie(0); | |
int n, k; | |
cin >> n >> k; | |
for (int i = 1; i <= n; i++) cin >> v[i]; | |
int res; | |
if (k == 1) { | |
res = inf; | |
for (int i = 1; i <= n; i++) res = min(res, v[i]); | |
} else if (k == 2) { | |
res = max(v[1], v[n]); | |
} else { | |
res = -inf; | |
for (int i = 1; i <= n; i++) res = max(res, v[i]); | |
} | |
cout << res << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment