public class Solution {
/**
* @param n: an integer
* @param k: an integer
* @return: how many problem can you accept
*/
public long canAccept(long n, int k) {
long left = 0;
long right = (long) Math.sqrt(2 * n / k);
while (left + 1 < right) {
long mid = left + (right - left) / 2;
if ((findTime(mid, k)) > n) {
right = mid;
} else {
left = mid;
}
}
if (findTime(right, k) <= n) return right;
return left;
}
private long findTime(long i, int k) {
return k * ((1 + i) * i / 2);
}
}