Sunteți pe pagina 1din 5

DICKY KAISAR UTOMO <5115100077>

BUSYMAN - I AM VERY BUSY


#greedy

I AM VERY BUSY
You are actually very busy man. You have a big schedule of activities. Your aim is to do as much as
activities as possible.

In the given figure, if you go to date with crush, you cannot participate in the coding contest and you cant
watch the movie. Also if you play DotA, you cant study for the exam. If you study for the exam you cant
sleep peacefully. The maximum number of activities that you can do for this schedule is 3.

Either you can

watch movie, play DotA and sleep peacefully (or)


date with crush, play DotA and sleep peacefully

0 <= start < end <= 1000000


DICKY KAISAR UTOMO <5115100077>

PSEUDOCODE with iterative

BusyMan_Iterative(n,go,stop) //n menyatakan jumlah aktifitas,go dan stop menyatakan interval time

1. int go, int stop, int mark=0


2. vector (pair(int,int) > v)
3. mark=1
4. for i=0 to n
5. //input go and stop
6. v.push_back(make_pair(stop,go))
7. Sort(v.begin(),v.end())
8. Int PresentVin = v(0).first
9. For i=1 to n
10. If v(i).second>=PresentFin
11. Mark++
12. PresentFin=v(i).first
13. Return mark

PSEUDOCODE with recursive

//int array(100001) sebagai variable global

int main()

1. While(n--)
2. Int test
3. //input test
4. Int i
5. For i=0 to test*2
6. //input array(i),array(i+1)
7. I+=2
8. Sort(0,test-1)
9. Return BusyMan_Recursive(0,test+1)
DICKY KAISAR UTOMO <5115100077>

Int BusyMan_Recursive(x,y) //x dan y menyatakan tima interval

1. int hasil-0
2. Int PresentFin=go+1
3. While PresentFin<=stop and array(PresentFin*2) < array(go*2+1)
4. PresentFin+=1
5. If (PresentFin<=stop)
6. Hasil=1
7. Return hasil + BusyMan_Recursive(PresentFin,stop)
8. Return hasil

Void sort(go,stop)

1. Int pivot, int temp, int temp1


2. If(go<stop)
3. Pivot=go
4. Int i=go
5. Int j=stop
6. While(i<j)
7. While (array(i*2+1) <= array(pivot*2+1) and i<stop)
8. I++
9. While (array(i*2+1) <= array(pivot*2+1) and i<stop)
10. j++
11. If(i<j)
12. Temp=array(i*2)
13. Temp1=array(i*2)
14. Array(i*2+1)=array(j*2+1)
15. Array(i*2)=array(j*2)
16. Array(j*2+1)=temp
17. Aray(j*2)=temp1
18. Temp=array(pivot*2+1)
19. Temp1=array(pivot*2)
20. Array(pivot*2+1)=array(j*2+1)
21. Array(pivot*2)=array(j*2)
22. Array(j*2+1)=temp
23. Aray(j*2)=temp1
24. sort(go, j-1)
25. sort(j+1, stop)
DICKY KAISAR UTOMO <5115100077>

DOKUMENTASI
DICKY KAISAR UTOMO <5115100077>

S-ar putea să vă placă și