// Codeforces Round #176 (Div. 2) B Pipeline
import java.io.*;
import java.io.ObjectInputStream.GetField;
import java.math.*;
import java.text.*;
import java.util.*;
//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;// change to false before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
Long n = in.nextLong();
Long k = in.nextLong();
if (n == 1) {
out.println(0);
return;
}
Long left = 2L;
Long right = k;
Long totSplitter = 0L;
Long minAns = Long.MAX_VALUE;
Long mid;
while (true) {
mid = (left + right) / 2;
totSplitter = GetOut(mid, k);
if (totSplitter >= n) {
left = mid + 1;
minAns = Math.min(minAns, k - mid + 1);
}
else {
right = mid - 1;
}
if (left > right)
break;
}
if (minAns == Long.MAX_VALUE)
out.println(-1);
else
out.println(minAns);
}
static long GetOut(long k1, long k)
{
return k1 + (k1 + k - 1) * (k - k1) / 2;
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
}
}
No comments:
Post a Comment