• + 0 comments

    I saw a lot of solutions here that are wrong. I do not know why the test cases do not catch it. One example where most of solutions will fail is for an input of 10 and 7. I hope the test cases are updated.

    A complete correct solution.

    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.math.*;
    import java.util.regex.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int p = in.nextInt();
            
            int s = p/2;
            
            int f = n%2==0 ? (n+1-p)/2 : (n-p)/2 ;
            
            int b = s<f ? s : f;
            
            System.out.println(b);
            
            
            // your code goes here
        }
    }