-
Notifications
You must be signed in to change notification settings - Fork 0
/
Angry Monk
198 lines (168 loc) · 3.14 KB
/
Angry Monk
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define int long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
const int MAX_N = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ld EPS = 1e-9;
bool primes[1000001];
const int N = 200005;
struct Node{
Node*arr[26];
bool flag = false;
};
class Trie {
private: Node*root;
public:
Trie() {
root = new Node();
}
void insert(string s) {
Node*curr = root;
for(char x:s){
int ind = x-'a';
if(curr->arr[ind]==NULL){
curr->arr[ind] = new Node();
}
curr = curr->arr[ind];
}
curr->flag = true;
}
bool search(string s) {
Node*curr = root;
for(char x:s){
int ind = x-'a';
if(curr->arr[ind]==NULL) return false;
else curr = curr->arr[ind];
}
return curr->flag;
}
bool startsWith(string s) {
Node*curr = root;
for(char x:s){
int ind = x-'a';
if(curr->arr[ind]==NULL) return false;
else curr = curr->arr[ind];
}
return true;
}
};
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
//-----------------------------------NUmber Theory----------------------
int inv(int n,int m){
return binpow(n,m-2,m);
}
void seive(){
int n = 1000001;
fill(primes,primes+n,true);
primes[0] = primes[1] = false;
for (int i = 2; i*i<=n; i++)
{
if(primes[i]){
for (int j =i*i; j<n; j = j+i)
{
primes[j] = false;
}
}
}
}
vector<int>primefactors(int n){
vector<int>ans;
for (int i = 2; i*i<=n; i++)
{
while (n%i==0)
{
n = n/i;
ans.push_back(i);
}
}
if(n>1){
ans.push_back(n);
}
return ans;
}
int fact[N], invfact[N];
int pow(int a, int b, int m)
{
int ans=1;
while(b)
{
if(b&1)
ans=(ans*a)%m;
b/=2;
a=(a*a)%m;
}
return ans;
}
int modinv(int k)
{
return pow(k, MOD-2, MOD);
}
void precompute()
{
fact[0]=fact[1]=1;
for(int i=2;i<N;i++)
{
fact[i]=fact[i-1]*i;
fact[i]%=MOD;
}
invfact[N-1]=modinv(fact[N-1]);
for(int i=N-2;i>=0;i--)
{
invfact[i]=invfact[i+1]*(i+1);
invfact[i]%=MOD;
}
}
int nCr(int n, int k)
{
return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}
// state ---->
//Transition -->
/*
*/
//Base Case --->
//Final Subproblem --->
//-----------------------------------------------------end----------------------------------------------------------
void solve() {
int k;
cin>>k;
int n;
cin>>n;
int arr[n];
for(int i = 0;i<n;i++){
cin>>arr[i];
}
sort(arr,arr+n);
int sum = 0;
int curr = 0;
for (int i = 0; i <n-1; i++)
{
sum = sum+arr[i];
curr = curr+arr[i]-1;
}
cout<<sum+curr<<"\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
solve();
}
}