
The Biggest Restaurant
|
All submissions for this problem are available.
### Read problems statements in [Hindi](http://www.codechef.com/download/translated/COOK112/hindi/BIGRES.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/COOK112/mandarin/BIGRES.pdf), [Russian](http://www.codechef.com/download/translated/COOK112/russian/BIGRES.pdf), [Vietnamese](http://www.codechef.com/download/translated/COOK112/vietnamese/BIGRES.pdf), and [Bengali](http://www.codechef.com/download/translated/COOK112/bengali/BIGRES.pdf) as well. Chef Ada is building a new restaurant in the following way: - First, $N$ points $X_1, X_2, \ldots, X_N$ are chosen on the $x$-axis. - Then, $N$ columns (numbered $1$ through $N$) are made. For simplicity, the columns are represented as vertical segments; for each valid $i$, the height of the $i$-th segment is $H_i$. - Ada assigns a column to each of the points $X_1, X_2, \ldots, X_N$ in an arbitrary way (each column must be assigned to exactly one point). - Finally, Ada constructs the roof of the restaurant, represented by a polyline with $N$ vertices. Let's denote the column assigned to the $i$-th point by $P_i$. For each valid $i$, the $i$-th of these vertices is $(X_i, H_{P_i})$, i.e. the polyline joins the tops of the columns from left to right. Ada wants the biggest restaurant. Help her choose the positions of the columns in such a way that the area below the roof is the biggest possible. Formally, she wants to maximise the area of the polygon whose perimeter is formed by the roof and the segments $(X_N, H_{P_N}) - (X_N, 0) - (X_1, 0) - (X_1, H_{P_1})$. Let $S$ be this maximum area; you should compute $2 \cdot S$ (it is guaranteed that $2 \cdot S$ is an integer). ### Input - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $X_i$ and $H_i$. ### Output For each test case, print a single line containing one integer $2 \cdot S$. ### Constraints - $1 \le T \le 3 \cdot 10^5$ - $2 \le N \le 10^5$ - $0 \le X_1 \lt X_2 \lt \ldots \lt X_N \le 2 \cdot 10^9$ - $1 \le H_i \le 10^9$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $10^6$ ### Example Input ``` 1 5 1 1 2 2 3 3 4 4 5 5 ``` ### Example Output ``` 27 ``` ### Explanation
Author: | alei |
Editorial | https://discuss.codechef.com/problems/BIGRES |
Tags | alei, basic-math, cook112, easy, greedy, taran_1407 |
Date Added: | 20-08-2019 |
Time Limit: | 1 sec |
Source Limit: | 50000 Bytes |
Languages: | C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS |
Comments
- Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. |
