-
Notifications
You must be signed in to change notification settings - Fork 1
/
P12015.f95
32 lines (32 loc) · 935 Bytes
/
P12015.f95
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
program P12015
implicit none
integer :: length
integer, dimension(1000000) :: sequence, rearranged
integer :: i
integer :: size
integer :: low, mid, high
read (*, *) length
read (*, *) (sequence(i), i = 1, length)
size = 1
rearranged(1) = sequence(1)
do i = 2, length
if (rearranged(size) < sequence(i)) then
size = size + 1
rearranged(size) = sequence(i)
else if (rearranged(size) > sequence(i)) then
low = 1
high = size
do while (low < high)
mid = (low + high) / 2
if (rearranged(mid) < sequence(i)) then
low = mid + 1
else
high = mid
end if
end do
mid = (low + high) / 2
rearranged(mid) = sequence(i)
end if
end do
write (*, '(I0)') size
end program P12015