codeforces-scrape

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

2199B.md (1608B)


      1 Source: https://codeforces.com/problemset/problem/2199/B
      2 
      3 B. Two Towers
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You have two towers made of blocks, standing next to each other. Initially, the height of the first tower is $a$, and the height of the second tower is $b$.
     22 
     23 In one action, you can:
     24 
     25 * take one block and place it on one of the towers, increasing its height by $1$;
     26 * or take two blocks and place one on each tower, increasing both heights by $1$. However, this can only be done if their heights are equal.
     27 
     28 Your goal is to make the height of the first tower equal to $c$, and the height of the second tower equal to $d$. What is the minimum number of actions you need to perform?
     29 
     30 Input
     31 
     32 The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
     33 
     34 Each test case consists of one line containing $4$ integers $a, b, c, d$ ($1 \le a \le c \le 10^8$; $1 \le b \le d \le 10^8$).
     35 
     36 Output
     37 
     38 For each test case, output one integer — the minimum number of actions that you have to perform.
     39 
     40 Example
     41 
     42 Input
     43 
     44 ```
     45 5
     46 
     47 1 2 3 5
     48 
     49 1 1 1 1
     50 
     51 2 6 3 8
     52 
     53 3 3 6 4
     54 
     55 2 4 7 7
     56 ```
     57 
     58 Output
     59 
     60 ```
     61 4
     62 
     63 0
     64 
     65 3
     66 
     67 3
     68 
     69 5
     70 ```
     71 
     72 Note
     73 
     74 In the first example, you can first place a block on the first tower, making the heights of both towers equal to $2$. Then, you can place one block on each tower, raising their heights to $3$. After that, you can place two blocks on the second tower, increasing its height to $5$. Thus, in $4$ moves, you can make the height of the first tower equal to $3$ and the second tower equal to $5$.