Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:04:17+00:00 2026-06-12T08:04:17+00:00

Possible Duplicate: Algorithm to find the maximum sum in a sequence of overlapping intervals

  • 0

Possible Duplicate:
Algorithm to find the maximum sum in a sequence of overlapping intervals

I was solving the following modified activity scheduling (Greedy approach) problem :

Given a set S of n activities with and start time, Si and fi, finish time of an ith activity. Also given weight wi ,the cost earned by Foo for doing ith activities.

The problem is to select the activities that maximizes foo earnings. We have to return the maximum cost that can be earn by foo.Assume that Foo can only work on a single activity at a time.

Note::

This is similar to classic Activity selection problem ,here the only difference is ,for each activities ,we are given a cost wi . And the goal here is too different –Instead of finding maximum size set of mutually compatible activities ,In this problem we have to find set of those activities that maximise foo total earnings .

Example

Total activities N=4
Si fi wi
0 1 4000
2 5 100
1 4 3000
4 5 2500

Max earning=9500 (Answer)

How do i modify the classical greedy activity selection algorithm ,for solving this problem . What logic should i use to solve the above problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:04:18+00:00Added an answer on June 12, 2026 at 8:04 am

    I don’t see how to solve this greedily. The solution I can see is dynamic programming, in which you have to solve the subproblem

    F(n) = what is the maximum profit that Foo can get by working only after day n?

    Then the recursive formulation is clear: We have that F(n) is either equal to F(n+1) (in the case in which Foo doesn’t work on day n), or equal to the maximum out of F(fi) + wi, for each activity that starts on time si=n .

    EDIT: Suppose the ending times of the activities are f0 <= f1 <= f2 <= … <= fN. Then the answer is F[f0] (what is the best profit working starting on time f0), and it can be calculated as:

    for n = N to 0:
        F[fn] = F[fn+1]
        for each activity (si, fi, wi):
             if si == fn: 
                 F[fn] = max(F[fn], F[fi] + wi)
    

    If the activities are sorted in non-increasing order based on their starting time, the complexity of this approach is linear in the number of activities (as you can stop the inner loop when si < N).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Find the maximum interval sum in a list of real numbers. I
Possible Duplicate: Algorithm to find the total number of connected sets in a matrix
Possible Duplicate: substring algorithm Given two strings, A and B, how to find the
Possible Duplicate: Solution to a recursive problem (code kata) give an algorithm to find
Possible Duplicate: Getting the submatrix with maximum sum? Given a 2-dimensional array of positive
Possible Duplicate: Algorithm to find Lucky Numbers I came across this question.A number is
Possible Duplicate: Algorithm to find minimum number of weighings required to find defective ball
Possible Duplicate: Peak-finding algorithm for Python/SciPy I'm looking to find local maxima in a
Possible Duplicate: Algorithm to compare two images I am looking for solution to find
Possible Duplicate: Worst-case O(n) algorithm for doing k-selection Given the following question : In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.