49 lines
946 B
Java
49 lines
946 B
Java
package chelper;
|
|
|
|
import java.util.SortedMap;
|
|
import java.util.TreeMap;
|
|
|
|
import io.InputReader;
|
|
import io.OutputWriter;
|
|
import misc.GCJSolution;
|
|
import misc.SimpleSavingChelperSolution;
|
|
|
|
|
|
public class TaskC extends GCJSolution {
|
|
|
|
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
|
wrapSolve(testNumber, in, out);
|
|
}
|
|
|
|
void add(SortedMap<Long, Long> map, long x, long c) {
|
|
map.putIfAbsent(x, 0L);
|
|
map.put(x, map.get(x) + c);
|
|
}
|
|
|
|
@Override
|
|
public void solve(int testNumber) {
|
|
long n = in.nextLong();
|
|
long k = in.nextLong();
|
|
|
|
long c = 0;
|
|
|
|
SortedMap<Long, Long> map = new TreeMap<>();
|
|
map.put(n, 1L);
|
|
|
|
while (true) {
|
|
long l = map.lastKey();
|
|
long lc = map.get(l);
|
|
map.remove(l);
|
|
|
|
if (c + lc >= k) {
|
|
out.println((l / 2) + " " + ((l - 1) / 2));
|
|
return;
|
|
}
|
|
c += lc;
|
|
|
|
add(map, l / 2, lc);
|
|
add(map, (l - 1) / 2, lc);
|
|
}
|
|
}
|
|
}
|