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 6672425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:30:24+00:00 2026-05-26T03:30:24+00:00

After a few busy nights my head isn’t working so well, but this needs

  • 0

After a few busy nights my head isn’t working so well, but this needs to be fixed yesterday, so I’m asking the more refreshed community of SO.

I’ve got a series of numbers. For example:

1, 5, 7, 13, 3, 3, 4, 1, 8, 6, 6, 6

I need to split this series into three parts so the sum of the numbers in all parts is as close as possible. The order of the numbers needs to be maintained, so the first part must consist of the first X numbers, the second – of the next Y numbers, and the third – of whatever is left.

What would be the algorithm to do this?

(Note: the actual problem is to arrange text paragraphs of differing heights into three columns. Paragraphs must maintain order (of course) and they may not be split in half. The columns should be as equal of height as possible.)

  • 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-05-26T03:30:25+00:00Added an answer on May 26, 2026 at 3:30 am

    First, we’ll need to define the goal better:

    Suppose the partial sums are A1,A2,A3, We are trying to minimize |A-A1|+|A-A2|+|A-A3|. A is the average: A=(A1+A2+A3)/3.

    Therefore, we are trying to minimize |A2+A3-2A1|+|A1+A3-2A2|+|A1+A2-2A3|.

    Let S denote the sum (which is constant): S=A1+A2+A3, so A3=S-A1-A2.

    We’re trying to minimize:

    |A2+S-A1-A2-2A1|+|A1+S-A1-A2-2A2|+|A1+A2-2S+2A1+2A2|=|S-3A1|+|S-3A2|+|3A1+SA2-2S|

    Denoting this function as f, we can do two loops O(n^2) and keep track of the minimum:

    Something like:

    for (x=1; x<items; x++)
    {
        A1= sum(Item[0]..Item[x-1])
        for (y=x; y<items; y++)
        {
            A2= sum(Item[x]..Item[y-1])
            calc f, if new minimum found -keep x,y
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Kinda of embarrassing to ask this question after few years working with Hibernate... I
Application closed after few seconds. I can see the JSON value in logcat but
I use $.mobile.changePage to go to another page. It success but after few second
After few weeks break, I'm trying to expand and extend my knowlege of templates
I need to implement Android application which will be expired after few days or
When the user click on Camera, it open next screen after few seconds it
After a few tests, I'm starting to reach the conclusion that a browser does
After a few harsh lessons I now always use OrdinalIgnoreCase when comparing Strings in
So after a few hours, I discovered the cause of a bug in my
Log4J is failing for us generally after a few hours of use in our

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.