Submission #3773757


Source Code Expand

program main
implicit None
integer(8)::n,x,s,i
integer(8),allocatable::a(:)

	read *,n,x
	allocate(a(n))
	read *,a
	call hsort(a,n)
	
	s = 0
	do i = 1,n
		s = s + a(i)
		if(s > x)then
			exit
		endif
	enddo
	
	if((x-s) >= 0) i = i-1
	if((x-s)/=0) i = i-1
	
	if(i < 0) i = 0
	
	print 101,i
	
101 format(i0)
end program main

subroutine makeheap(a,n)
Implicit None
	integer(8)::n,i,c1,c2,p,t,m
	integer(8)::a(n)
	
	do i = n/2,1,-1
		p = i; c1 = i * 2
		do while (c1 <= n)
			c2 = c1 + 1
			if(c2 <= n .and. a(c2) > a(c1)) c1 = c2
			if(a(p) < a(c1))then
				t = a(p)
				a(p) = a(c1)
				a(c1) = t
				p = c1
				c1 = p*2
				else
					exit
			endif
		enddo
	enddo
	
end subroutine makeheap

subroutine hsort(a,n)
Implicit None
	integer(8)::n,t,i,p,c1,c2,j
	integer(8)::a(n)
	
	call makeheap(a,n)
	
	do i = n,2,-1
		t = a(i)
		a(i) = a(1)
		a(1) = t
		
		p = 1
		do
			c1 = p*2
			if (c1 >= i) exit
			
			c2 = c1 +1
			if(c2 < i .and. a(c2) > a(c1))then
					c1 = c2
			endif
			
			if(a(c1) >a(p))then
				t = a(p)
				a(p) = a(c1)
				a(c1) = t
				p = c1
				else
					exit
			endif
		enddo
	enddo
end subroutine hsort

Submission Info

Submission Time
Task A - Candy Distribution Again
User Tategami
Language Fortran (gfortran v4.8.4)
Score 200
Code Size 1204 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 4
AC × 12
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
0_03.txt AC 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 1 ms 256 KB
1_04.txt AC 1 ms 256 KB
1_05.txt AC 1 ms 256 KB
1_06.txt AC 1 ms 256 KB
1_07.txt AC 1 ms 256 KB