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

  • SEARCH
  • Home
  • 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 8860873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:21:42+00:00 2026-06-14T15:21:42+00:00

I’ll try to explain it better. So k = 2. In[]profits = new {1,

  • 0

I’ll try to explain it better.

So k = 2.
In[]profits = new {1, 2, 3, 1, 6, 10}

For the first part it should be:

1,2,3

Then look for the least value in {1,2,3} which is 1. Then add that to the next value which is 1. So it would be 1+1. The outcome would be {2,3,2}. Again look for the least value which is 2 and add it to the next value 6. So it would be 2+6. The outcome would be {3, 2, 8}. Finally, for the least value in {3,2,8} and add it to the next value 10. So it would be and 10+2. The outcome is {2, 8, 10}. Then look for the least value in that which is 2.

If you guys could at least guide me on how to do this?

This is the tester:

import java.util.Arrays ;

 /**
 Presents some problems to the BillBoard class.
 */

public class BillboardTester {

    public static void main(String[] args) {
    int[] profits = new int[]{1, 2, 3, 1, 6, 10} ;

        int k = 2 ;

        System.out.println("Profits: " + Arrays.toString(profits) + "   k = " + k)  ;

        Billboard bb = new Billboard(profits, k) ;
        System.out.println("Maximum Profit = " + bb.maximumProfit()) ;
        System.out.println(bb) ;

        k = 3 ;
        profits = new int[]{7, 4, 5, 6, 1, 7, 8, 9, 2, 5} ;
        System.out.println("Profits: " + Arrays.toString(profits) + "   k = " + k)  ;
        bb = new Billboard(profits, k) ;
        System.out.println("Maximum Profit = " + bb.maximumProfit()) ;
        System.out.println(bb) ;
    }
}

This is what I have so far for the class:

public class Billboard {
    private int maximumprofit; // The max profit 
    private int finalcost; // The final cost of removing the billboards

    public Billboard(int[]profits, int k) {
        for (int i = 0; i < profits.length; i++) {
            maximumprofit+= profits[i];
        }
    }

    public int maximumProfit() {
        return maximumprofit;
    }
}
  • 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-14T15:21:43+00:00Added an answer on June 14, 2026 at 3:21 pm

    If I understand your problem correctly, you have k+1 possible totals, and you add each new element of profits to the LOWEST current total profit no matter what it is. So in your example, it’s really

    • 1, 2, 3
    • 1+1=2, 2, 3
    • 2+6=8, 2, 3
    • 8, 2+10=12, 3

    For a final array of

    • 8, 12, 3 -> Lowest value is actually 3

    If this is what you meant (you never said what k is), this code will do the job. I left a line of debugging code in there to help you check for correctness.

    public class Billboard
    {
        private int[] profits;
        private int k;
        public Billboard(int[]profits, int k)
        {
            this.profits = profits;
            this.k = k+1; // I changed this to k+1 because you have 3 totals with k = 2
        }
        public int maximumProfit() {
            int[] bottom = new int[k];
    
            for(int i = 0; i < profits.length; i++) {
                int minIndex = 0;
                int min = Integer.MAX_VALUE;
                for (int j = 0; j < k; j++) {
                    if (bottom[j] < min) {
                        minIndex = j;
                        min = bottom[j];
                    }
                }
                bottom[minIndex] += profits[i];
            }
    
            int min = Integer.MAX_VALUE;
            for(int i = 0; i < k; i++) {
                System.out.println("TestDump: #"+i+" is: " + bottom[i]);
                if (bottom[i] < min) {
                    min = bottom[i];
                }
            }
    
            return min;
        }
    
        public static void main(String args[]) {
            Billboard bb = new Billboard(new int[]{1,2,3,1,6,10}, 2);
            System.out.println("Maximum profit = " + bb.maximumProfit());
        }
    }
    

    This code outputs

    TestDump: #0 is: 8
    TestDump: #1 is: 12
    TestDump: #2 is: 3
    Maximum profit = 3
    

    To change what the Billboard class outputs when you put it in System.out.println(bb), you have to override the toString method of the Billboard class, i.e.

    @Override
    public String toString() {
        return (new StringBuider(totalProfit - maxProfit)).toString();
    }
    

    Assuming you set the fields in the class to have the correct values earlier.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from

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.