-
Notifications
You must be signed in to change notification settings - Fork 0
/
KafCake.c
62 lines (41 loc) · 993 Bytes
/
KafCake.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
//In the Name of God
#include <stdio.h>
#include <stdlib.h>
#define max(x, y) (((x) > (y)) ? (x) : (y))
#define min(x, y) (((x) < (y)) ? (x) : (y))
int c[6000];
int n ;
int k ;
int findMx ( int x ) {
int Max1 = 0 ;
int Max2 = 0 ;
for ( int i = 0 ; i < x ; i ++ )
Max1 = max ( Max1 , c[i] ) ;
for ( int i = x ; i < n ; i ++ )
Max2 = max ( Max2 , c[i] ) ;
return min ( Max1 , Max2 ) ;
}
int main () {
scanf ("%d%d" , &n , &k ) ;
for ( int i = 0 ; i < n ; i ++ )
scanf ( "%d" , &c[i] ) ;
int Min = 1e5 ;
int Max = 0 ;
for ( int i = 0 ; i < n ; i ++ ) {
Min = min ( Min , c[i] ) ;
Max = max ( Max , c[i] ) ;
}
if ( k == 1 ) {
printf ("%d" , Max ) ;
return 0 ;
}
if ( k >= 3 ) {
printf ("%d" , Min ) ;
return 0 ;
}
Min = 1e5 ;
for ( int i = 1 ; i < n ; i ++ )
Min = min ( Min , findMx(i) ) ;
printf ("%d" , Min ) ;
return 0 ;
}