Bessie's Birthday Cake (Easy Version) (Codeforces 1942C1)
Tags: Greedy, geometry

Proof Geometric Construction Can Solve All Love Affairs - manbo-p⠀This is the easy version of the problem. The only difference between the two versions is the constraint on $$$y$$$. In this version $$$y = 0$$$. You can make hacks only if both versions are solved.Bessie has received a birthday cake from her best friend Elsie, and it came in the form of a regular polygon with $$$n$$$ sides. The vertices of the cake are numbered from $$$1$$$ to $$$n$$$ clockwise. You and Bessie are going to choose some of those vertices to cut non-intersecting diagonals into the cake. In other words, the endpoints of the diagonals must be part of the chosen vertices.Bessie would only like to give out pieces of cake which result in a triangle to keep consistency. The size of the pieces doesn't matter, and the whole cake does not have to be separated into all triangles (other shapes are allowed in the cake, but those will not be counted). Bessie has already chosen $$$x$$$ of those vertices that can be used to form diagonals. She wants you to choose no more than $$$y$$$ other vertices such that the number of triangular pieces of cake she can give out is maximized.What is the maximum number of triangular pieces of cake Bessie can give out?

Input: The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.The first line of each test case consists of three integers, $$$n$$$, $$$x$$$, and $$$y$$$ ($$$4 \leq n \leq 10^9$$$, $$$2 \leq x \leq \min(n, 2 \cdot 10^5)$$$, $$$y = 0$$$) — the number of sides of the polygon, number of vertices Bessie has chosen, and the maximum number of other vertices you can choose.The second line consists of $$$x$$$ distinct integers from $$$1$$$ to $$$n$$$, representing the vertices Bessie has chosen.It is guaranteed the sum of $$$x$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. 

Output: For each test case, output a single integer: the maximum number of non-intersecting triangular pieces of cake she can give out.

Note: In test cases $$$1$$$, $$$2$$$ and $$$3$$$, you can get $$$2$$$, $$$6$$$ and $$$2$$$ non-intersecting triangular pieces of cake, respectively. A possible construction is shown in the following pictures:The green dots represent vertices that can be used, the blue lines represent diagonals that are drawn, and the red numbers represent triangles that are counted.  

Sample Inputs:
3
8 4 0
1 6 2 5
8 8 0
1 3 2 5 4 6 7 8
4 2 0
1 3

Sample Outputs:
2
6
2

Solution (Python):
from math import gcd
import sys

def lsinp():
    return sys.stdin.readline().strip().split()

def liinp():
    return list(map(int, sys.stdin.readline().strip().split()))

def sinp():
    return sys.stdin.readline().strip()

def iinp():
    return int(sys.stdin.readline().strip())
for _ in range(iinp()):
    (n, x, y) = liinp()
    nums = liinp()
    nums.sort()
    ans = 0
    ans += len(nums) - 2
    for i in range(1, len(nums)):
        if nums[i] - nums[i - 1] == 2:
            ans += 1
    if x > 1 and n - nums[x - 1] + (nums[0] - 1) == 1:
        ans += 1
    print(ans)

Solution (Python):
def calculate_triangular_pieces(sides, chosen, chosen_vertices):
    chosen_vertices.sort()
    result = chosen - 2
    for i in range(chosen - 1):
        if chosen_vertices[i] + 2 == chosen_vertices[i + 1]:
            result += 1
    if chosen >= 2 and (chosen_vertices[-1] + 2) % sides == chosen_vertices[0]:
        result += 1
    return result
if __name__ == '__main__':
    num_cases = int(input())
    for _ in range(num_cases):
        (sides, chosen, _) = map(int, input().split())
        chosen_vertices = list(map(int, input().split()))
        result = calculate_triangular_pieces(sides, chosen, chosen_vertices)
        print(result)

Solution (Python):
def main():
    t = int(input())
    for _ in range(t):
        (n, x, y) = map(int, input().split())
        arr = list(map(int, input().split()))
        arr.sort()
        ans = x - 2
        for i in range(x - 1):
            if arr[i] + 2 == arr[i + 1]:
                ans += 1
        if x >= 2 and (arr[-1] + 2) % n == arr[0]:
            ans += 1
        print(ans)
if __name__ == '__main__':
    main()