Counterexamples to Claim that A = (10,1,1,10) for B = (10,1,1,10)?

AI Thread Summary
The discussion centers on finding the maximum sum of absolute differences in a sequence defined by constraints on its elements. The user is confident that each element can only be 1 or its corresponding upper limit, bi. They explore two potential patterns for the sequence but seek counterexamples to validate their assumptions. A key insight is that while alternating patterns might seem optimal, they do not necessarily yield the maximum sum in all cases. The specific example of the sequence B = (10,1,1,10) illustrates the need for a more flexible approach in constructing sequence A.
SlurrerOfSpeech
Messages
141
Reaction score
11
I'm trying to solve a problem that amounts to:

Given b0, ..., bn-1 where1 <= bi, find the max of |a0 - a1| + |a1 - a2| + ... + |an-2 - an-1| where 1 <= ai <= bi.

I'm 100% confident that each ai is either 1 or bi.

I'm 90% confident that the elements a0, ..., an-1 are either

1, b0, 1, b1, ...,

or

b0, 1, b1, 1, ...

Are there any simple counterexamples?
 
Technology news on Phys.org
Can you give a context for your question? Is this some intuitive problem or is it based on some concrete example that someone might already know about?
 
SlurrerOfSpeech said:
Are there any simple counterexamples?

it's easy to see, that for all ai-1 and ai+1, ai has to be 1 or bi.
- if ai is smaller than both ai-1 and ai+1, setting it to 1 will make the sum bigger.
- if ai is biggger than both ai-1 and ai+1, setting it to bi will make the sum bigger.
- if ai is between ai-1 and ai+1 setting it to 1 or to bi
will make the sum bigger.
The only case where the last possibility doesn't work, is when one of the neigbours is 1 and the other >= b. In that case the maximum sum is the same whatever ai is.
You can force such a situation with a 1,2,3,1 sequence. a1 can be anything <=2.
A non-conforming sequence with a larger sum of differences isn't possible.
 
jedishrfu said:
Can you give a context for your question? Is this some intuitive problem or is it based on some concrete example that someone might already know about?

An algorithms problem I'm trying to solve https://www.hackerrank.com/challenges/sherlock-and-cost

The solution I tried is essentially

X = [1, b0, 1, b1, ... ]
Y =[b0, 1, b1, 1, ... ]
max(diffs(X), diffs(Y)]

and was surprised that it didn't pass all test cases.
 
  • Like
Likes jedishrfu
To get the maximum, all ai can be either 1 or bi, but it doesn't have to be an alternating pattern of 1s and bis.
B = (10,1,1,10) needs A = (10,1,1,10)
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top