-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBessies_Birthday_Cake_Easy_Version.cpp
More file actions
40 lines (31 loc) · 1.11 KB
/
Bessies_Birthday_Cake_Easy_Version.cpp
File metadata and controls
40 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// birthday cake = n sided polygon numbered 1 to n clockwise
// bessie wants to give only triangle pieces(size doesn't matter)
// find max number of triangles she can give out
// she has choosen x vertices and we can choose y = 0 vertices for making diagonals
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll calc_dis(ll x, ll y, ll total){
if(x <= y)
return y - x;
return total - x + y;
}
inline int nxt(int x, int n) { return x == n ? 1 : x + 1; }
int main(){
ll testcases;
cin >> testcases;
for (ll testcase = 0; testcase < testcases; testcase++){
ll n, x, y;
cin >> n >> x >> y;
vector<ll> points(x);
for (ll i = 0; i < x; i++) // Fixed to read only 'x' points
cin >> points[i];
sort(points.begin(), points.end());
ll ans = max(0LL, x - 2); // Start with x - 2 triangles if x >= 3
for (ll i = 0; i < x; i++){
// Check if two consecutive points are 2 edges apart
ans += (calc_dis(points[i], points[nxt(i + 1, x) - 1], n) == 2);
}
cout << ans << endl;
}
}