-
Notifications
You must be signed in to change notification settings - Fork 0
/
airport.c
53 lines (40 loc) · 847 Bytes
/
airport.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
#include <stdio.h>
#include <stdlib.h>
int main(){
int passengers, planes, * seats, max = 0, min = 0;
int i, j, aux;
scanf("%d %d", &passengers, &planes);
seats = (int *) malloc(sizeof(int) * planes);
for(i = 0; i < planes; i++){
scanf("%d", &seats[i]);
}
for(i = 0; i < planes; i++){
for(j = i + 1; j < planes; j++){
if(seats[j] > seats[i]){
aux = seats[i];
seats[i] = seats[j];
seats[j] = aux;
}
}
}
int k = 0, tmp = seats[k];
for(i = 0; i < passengers; i++){
min += (tmp --);
if(tmp == 0)
tmp = seats[++ k];
}
for(i = 0; i < passengers; i++){
max += seats[0];
seats[0] -= 1;
for (k = 1; k < planes; k++){
if (seats[k - 1] >= seats[k])
break;
tmp = seats[k];
seats[k] = seats[k - 1];
seats[k-1] = tmp;
}
}
printf("%d %d\n", max, min);
free(seats);
return 0;
}