-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.cpp
More file actions
63 lines (46 loc) · 1007 Bytes
/
template.cpp
File metadata and controls
63 lines (46 loc) · 1007 Bytes
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
/**
* author: israk_kayum
**/
#include <bits/stdc++.h>
using namespace std;
// Macros for frequently used commands
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cerr << #x << " = " << (x) << endl;
#define endl '\n'
// Typedefs for commonly used data types
typedef long long ll;
// Constants
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LLINF = 1e18;
// const int N = 1e5+10;
// vector<bool> isPrime(N, 1);
// vector<int> lp(N, 0), hp(N, 0);
// main function
int main()
{
fastio;
int t;
cin >> t;
while(t--){
int n, k;
cin >> n >> k;
vector<int> a(k);
for (int i = 0; i < k; ++i)
{
cin >> a[i];
}
priority_queue<int, vector<int>, greater<int>> p(a.begin(), a.end());
int op = 0;
while(p.size() > 1){
int sm = p.top();
p.pop();
int seSm = p.top();
p.pop();
p.push(sm + seSm);
op++;
}
cout << op << endl;
}
return 0;
}