fork download
  1. #include <iostream>
  2. using namespace std;
  3. void printMaxActivities(int s[], int f[], int n, int k[] )
  4. {
  5. int i, j;
  6.  
  7. printf (" new Following activities are selected \n");
  8.  
  9. // The first activity always gets selected
  10. i = 0;
  11. printf("%d ", i);
  12.  
  13. // Consider rest of the activities
  14. for (j = 1; j < n; j++)
  15. {
  16. // If this activity has start time greater than or equal to the finish
  17. // time of previously selected activity, then select it
  18. if ((s[j] >= f[i]) &&( k[j-1]!=k[j]))
  19. {
  20. printf (" %d ", j);
  21. i = j;
  22. }
  23. }
  24. }
  25.  
  26. // driver program to test above function
  27. int main()
  28. {
  29. int s[] = {10, 100,150, 200};
  30. int f[] = {100,200,500,300};
  31. int k[]={1,2,2,2};
  32. int n = sizeof(s)/sizeof(s[0]);
  33. printMaxActivities(s, f, n, k);
  34. getchar();
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 3144KB
stdin
Standard input is empty
stdout
 new Following activities are selected 
0  1