HINT 1
HINT 2
HINT 3
HINT 1
HINT 2
HINT 3
HINT 4
HINT 1
HINT 2
5A. K-th Number in the Union of Segments
HINT 1
HINT 1
HINT 2
HINT 1
HINT 2
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Average should be in double not int or long long.
Any length is ok as long as the average is maximum.
Try a test case that all number is 0.
It is a DAG so we can use top sort + DP to get shortest path.
Binary search for the average, minus average on every edge.
If the shortest path is <= 0, it means we can have an even lower average. If the shortest path is > 0, it means this average is too high. Note, we don't need to find a path that is exactly 0 cost. Binary search will help us narrow down.
1 might not be the only source, so we need to push all in degree 0 to queue first.
(a+b)/(c+d) > m => a+b > (c+d)*m => a-m*c + b-m*d > 0
Binary search for m.
5A. K-th Number in the Union of Segments
Just follow what theory says
k should be 0 indexed for the theory, so [1, n^2] becomes [0, n^2-1]. Because cnt(x) could return 0, we need k to start from 0, otherwise 1 will be skipped.
There is a trick to get O(n) for cnt(x). Start from bottom left and count towards upper right, if mid > i*j, move j, otherwise move i.
k should be 0 indexed.
Sort both array and use two pointers method for cnt(x). Start from 0 of first array and start from n-1 of second array.
Name |
---|
have you read the terms of agreement?
Personally I don't see the point of the agreement.
USELESS ALGORITHM
that's why you are a newbie