This problem is a variation of binary search, but be very careful about integer overflow when summing large numbers. The correct way to compute the midpoint is left + (right - left) / 2. I used long long instead.
| |
This problem is a variation of binary search, but be very careful about integer overflow when summing large numbers. The correct way to compute the midpoint is left + (right - left) / 2. I used long long instead.
| |