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

Click For Summary
SUMMARY

The discussion centers on the problem of maximizing the sum of absolute differences in a sequence defined by constraints on its elements, specifically for the sequence B = (10,1,1,10). The participants assert that each element ai must be either 1 or bi, leading to two potential configurations: X = [1, b0, 1, b1, ...] and Y = [b0, 1, b1, 1, ...]. A counterexample is provided with the sequence (1,2,3,1), demonstrating that the maximum sum of differences can be achieved without adhering to an alternating pattern of 1s and bis. The conclusion emphasizes that while the maximum sum can be derived from the constraints, it does not necessitate a strict alternating arrangement.

PREREQUISITES
  • Understanding of absolute difference calculations in sequences
  • Familiarity with algorithmic problem-solving techniques
  • Knowledge of sequence manipulation and constraints
  • Experience with competitive programming platforms like HackerRank
NEXT STEPS
  • Study the problem-solving techniques for maximizing sums in constrained sequences
  • Explore the HackerRank challenge "Sherlock and Cost" for practical application
  • Learn about dynamic programming approaches to similar algorithmic problems
  • Investigate counterexample generation in algorithm design
USEFUL FOR

Algorithm developers, competitive programmers, and anyone interested in optimizing sequences under specific constraints will benefit from this discussion.

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   Reactions: 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)
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K