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 | tourist | 4009 |
2 | jiangly | 3839 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3612 |
7 | Geothermal | 3569 |
8 | ecnerwala | 3494 |
9 | Um_nik | 3396 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 164 |
2 | Um_nik | 163 |
3 | atcoder_official | 159 |
4 | cry | 158 |
4 | -is-this-fft- | 158 |
6 | awoo | 155 |
7 | adamant | 154 |
7 | nor | 154 |
9 | TheScrasse | 153 |
10 | Dominater069 | 152 |
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)=
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?