codeforces-scrape

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

1342A.md (1706B)


      1 Source: https://codeforces.com/problemset/problem/1342/A
      2 
      3 A. Road To Zero
      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 You are given two integers $x$ and $y$. You can perform two types of operations:
     22 
     23 1. Pay $a$ dollars and increase or decrease any of these integers by $1$. For example, if $x = 0$ and $y = 7$ there are four possible outcomes after this operation:
     24    * $x = 0$, $y = 6$;
     25    * $x = 0$, $y = 8$;
     26    * $x = -1$, $y = 7$;
     27    * $x = 1$, $y = 7$.
     28 2. Pay $b$ dollars and increase or decrease both integers by $1$. For example, if $x = 0$ and $y = 7$ there are two possible outcomes after this operation:
     29    * $x = -1$, $y = 6$;
     30    * $x = 1$, $y = 8$.
     31 
     32 Your goal is to make both given integers equal zero simultaneously, i.e. $x = y = 0$. There are no other requirements. In particular, it is possible to move from $x=1$, $y=0$ to $x=y=0$.
     33 
     34 Calculate the minimum amount of dollars you have to spend on it.
     35 
     36 Input
     37 
     38 The first line contains one integer $t$ ($1 \le t \le 100$) — the number of testcases.
     39 
     40 The first line of each test case contains two integers $x$ and $y$ ($0 \le x, y \le 10^9$).
     41 
     42 The second line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
     43 
     44 Output
     45 
     46 For each test case print one integer — the minimum amount of dollars you have to spend.
     47 
     48 Example
     49 
     50 Input
     51 
     52 ```
     53 2
     54 1 3
     55 391 555
     56 0 0
     57 9 4
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 1337
     64 0
     65 ```
     66 
     67 Note
     68 
     69 In the first test case you can perform the following sequence of operations: first, second, first. This way you spend $391 + 555 + 391 = 1337$ dollars.
     70 
     71 In the second test case both integers are equal to zero initially, so you dont' have to spend money.