-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path51866.cpp
49 lines (44 loc) · 789 Bytes
/
51866.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
int arr[10000];
int main()
{
int n,k;
cin>>n>>k;
int maxi=-1;
int mini=10000;
for(int i=1;i<=n;i++)
{
cin>>arr[i];
if(maxi<arr[i]) maxi=arr[i];
if(mini>arr[i]) mini=arr[i];
}
if(k==1)
{
cout<<maxi<<endl;
return 0;
}
if(k==2)
{
int maxx=0;
int minn=10000;
for(int i=1;i<=n;i++)
{
if(maxx<arr[i]) maxx=arr[i];
minn=min(minn,maxx);
}
maxx=0;
for(int i=n;i>=1;i--)
{
if(maxx<arr[i]) maxx=arr[i];
minn=min(minn,maxx);
}
cout<<minn<<endl;
}
if(k>2)
{
cout<<mini<<endl;
return 0;
}
return 0;
}