codeforces-scrape

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

1620B.md (2595B)


      1 Source: https://codeforces.com/problemset/problem/1620/B
      2 
      3 B. Triangles on a Rectangle
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 A rectangle with its opposite corners in $(0, 0)$ and $(w, h)$ and sides parallel to the axes is drawn on a plane.
     22 
     23 You are given a list of lattice points such that each point lies on a side of a rectangle but not in its corner. Also, there are at least two points on every side of a rectangle.
     24 
     25 Your task is to choose three points in such a way that:
     26 
     27 * exactly two of them belong to the same side of a rectangle;
     28 * the area of a triangle formed by them is maximum possible.
     29 
     30 Print the doubled area of this triangle. It can be shown that the doubled area of any triangle formed by lattice points is always an integer.
     31 
     32 Input
     33 
     34 The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases.
     35 
     36 The first line of each testcase contains two integers $w$ and $h$ ($3 \le w, h \le 10^6$) — the coordinates of the corner of a rectangle.
     37 
     38 The next two lines contain the description of the points on two horizontal sides. First, an integer $k$ ($2 \le k \le 2 \cdot 10^5$) — the number of points. Then, $k$ integers $x_1 \lt x_2 \lt \dots \lt x_k$ ($0 \lt x_i \lt w$) — the $x$ coordinates of the points in the ascending order. The $y$ coordinate for the first line is $0$ and for the second line is $h$.
     39 
     40 The next two lines contain the description of the points on two vertical sides. First, an integer $k$ ($2 \le k \le 2 \cdot 10^5$) — the number of points. Then, $k$ integers $y_1 \lt y_2 \lt \dots \lt y_k$ ($0 \lt y_i \lt h$) — the $y$ coordinates of the points in the ascending order. The $x$ coordinate for the first line is $0$ and for the second line is $w$.
     41 
     42 The total number of points on all sides in all testcases doesn't exceed $2 \cdot 10^5$.
     43 
     44 Output
     45 
     46 For each testcase print a single integer — the doubled maximum area of a triangle formed by such three points that exactly two of them belong to the same side.
     47 
     48 Example
     49 
     50 Input
     51 
     52 ```
     53 3
     54 5 8
     55 2 1 2
     56 3 2 3 4
     57 3 1 4 6
     58 2 4 5
     59 10 7
     60 2 3 9
     61 2 1 7
     62 3 1 3 4
     63 3 4 5 6
     64 11 5
     65 3 1 6 8
     66 3 3 6 8
     67 3 1 3 4
     68 2 2 4
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 25
     75 42
     76 35
     77 ```
     78 
     79 Note
     80 
     81 The points in the first testcase of the example:
     82 
     83 * $(1, 0)$, $(2, 0)$;
     84 * $(2, 8)$, $(3, 8)$, $(4, 8)$;
     85 * $(0, 1)$, $(0, 4)$, $(0, 6)$;
     86 * $(5, 4)$, $(5, 5)$.
     87 
     88 The largest triangle is formed by points $(0, 1)$, $(0, 6)$ and $(5, 4)$ — its area is $\frac{25}{2}$. Thus, the doubled area is $25$. Two points that are on the same side are: $(0, 1)$ and $(0, 6)$.