Hello !
May anyone help me to solve this problem ?
https://atcoder.jp/contests/abc172/tasks/abc172_c?lang=en
Thank You.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Hello !
Thank You.
Name |
---|
create prefix sums on A and B arrays.
use binary search.
let's choose array A arbitrary to loop over all of its prefix sums and firstly check if this prefix sum is less than or equal to k.
let the current prefix sum of A is su ,Then calculate rem=k-su and find rem in the prefix sum array of B using binary search ,then update the answer for each sum in A.
You can see that the more books you read on the desk A, the less books you will read on the desk B. So there's no need to use binary search, you can simply calculate the number of books on the dest B from the previous value.
The time complexity: $$$O(n + m)$$$, a bit faster the binary search $$$O(n\log{m})$$$.
Thank you !