codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1023B.md (1645B)


      1 Source: https://codeforces.com/problemset/problem/1023/B
      2 
      3 B. Pair of Toys
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Tanechka is shopping in the toy shop. There are exactly $n$ toys in the shop for sale, the cost of the $i$-th toy is $i$ burles. She wants to choose two toys in such a way that their total cost is $k$ burles. How many ways to do that does she have?
     22 
     23 Each toy appears in the shop exactly once. Pairs $(a, b)$ and $(b, a)$ are considered equal. Pairs $(a, b)$, where $a=b$, are not allowed.
     24 
     25 Input
     26 
     27 The first line of the input contains two integers $n$, $k$ ($1 \le n, k \le 10^{14}$) — the number of toys and the expected total cost of the pair of toys.
     28 
     29 Output
     30 
     31 Print the number of ways to choose the pair of toys satisfying the condition above. Print 0, if Tanechka can choose no pair of toys in such a way that their total cost is $k$ burles.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 8 5
     39 ```
     40 
     41 Output
     42 
     43 ```
     44 2
     45 ```
     46 
     47 Input
     48 
     49 ```
     50 8 15
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 1
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 7 20
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 0
     69 ```
     70 
     71 Input
     72 
     73 ```
     74 1000000000000 1000000000001
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 500000000000
     81 ```
     82 
     83 Note
     84 
     85 In the first example Tanechka can choose the pair of toys ($1, 4$) or the pair of toys ($2, 3$).
     86 
     87 In the second example Tanechka can choose only the pair of toys ($7, 8$).
     88 
     89 In the third example choosing any pair of toys will lead to the total cost less than $20$. So the answer is 0.
     90 
     91 In the fourth example she can choose the following pairs: $(1, 1000000000000)$, $(2, 999999999999)$, $(3, 999999999998)$, ..., $(500000000000, 500000000001)$. The number of such pairs is exactly $500000000000$.