git reimport
This commit is contained in:
48
archive/2017.04/2017.04.09 - unsorted/TaskC.java
Normal file
48
archive/2017.04/2017.04.09 - unsorted/TaskC.java
Normal file
@@ -0,0 +1,48 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user