Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

liveoverflow's blog

By liveoverflow, history, 5 weeks ago, In English,

There are 4 arrays of A, B, C, D of size N, we have to find

max( | A[i]-A[j] | + | B[i]-B[j] | + | C[i]-C[j] | + | D[i]-D[j] | + | i-j |)

where 1<=i<j<=n ; 1<N<=10^5; 1<=A[i],B[i],C[i],D[i]<=10^9

sample input :
5
5 7 6 3 9
7 9 2 7 5
1 9 9 3 3
8 4 1 10 5

sample output : 24

 
 
 
 
  • Vote: I like it
  • -10
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by liveoverflow (previous revision, new revision, compare).

»
5 weeks ago, # |
  Vote: I like it -7 Vote: I do not like it

can you provide link to the problem?

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I don't have the link, sorry

    • »
      »
      »
      5 weeks ago, # ^ |
      Rev. 2   Vote: I like it +4 Vote: I do not like it

      Your problem is an extension of an Interview problem.

      You are given an array of N integers. Return maximum value of |A[i] - A[j]| + |i - j| for all 1 ≤ i, j ≤ N. in O(n) time complexity link to the problem

      You should first try this problem and then come back to your problem. It will help.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by liveoverflow (previous revision, new revision, compare).

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by liveoverflow (previous revision, new revision, compare).

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

What is the time limit?

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

It seems all A[i] are positive, is there an upper limit?