Given an array of size n.You need to select those two different indices such that quirk between them is maximum.Quirk Q(i,j)=

# | User | Rating |
---|---|---|

1 | jiangly | 3640 |

2 | Benq | 3593 |

3 | tourist | 3572 |

4 | orzdevinwang | 3561 |

5 | cnnfls_csy | 3539 |

6 | ecnerwala | 3534 |

7 | Radewoosh | 3532 |

8 | gyh20 | 3447 |

9 | Rebelz | 3409 |

10 | Geothermal | 3408 |

# | User | Contrib. |
---|---|---|

1 | maomao90 | 174 |

2 | awoo | 164 |

3 | adamant | 163 |

4 | TheScrasse | 159 |

5 | nor | 158 |

6 | maroonrk | 156 |

7 | -is-this-fft- | 151 |

8 | SecondThread | 147 |

9 | orz | 146 |

10 | pajenegod | 145 |

Given an array of size n.You need to select those two different indices such that quirk between them is maximum.Quirk Q(i,j)=

↑

↓

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/23/2024 23:11:51 (i1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Auto comment: topic has been updated by ram396 (previous revision, new revision, compare).Can elements of A be negative?

No

Well if elements aren't negative then j should always be equal to n. And i you can traverse in linear time to find the maximum.

Edit: only if c is +ve, otherwise j can be other things.

If $$$A[i]$$$ or $$$c$$$ is allowed to be negative:

Note that:

We define the following functions:

For each $$$j$$$, you need to find $$$i$$$ such that $$$F(j) + M(i)j + C(i)$$$ is maximized. You can use convex hull trick to do so in $$$O(N \lg N)$$$ time.

That is a wonderful new thing which probably won't be useful for me to learn at this stage, but can you take a quick look at the latest question I asked in my blogs here? I think this problem can be solved using what you call a "convex hull trick" ? Am I right?. In brief I want the maximum of $$$a_1(K - i) - b_1, a_2(K - i) - b_2, \ldots, a_n(K - i) - b_n$$$ after each time I change i from 0 to K — 1.

can u provide the code?