forked from TheRealJishnu/Algorithm_sem_4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.cpp
More file actions
41 lines (35 loc) · 712 Bytes
/
temp.cpp
File metadata and controls
41 lines (35 loc) · 712 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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
ll n, a , b;
cin >> a >> b >> n;
vector<ll> tool(n);
for(auto &e : tool) cin >> e;
ll count = 0, tim = b;
sort(tool.begin(), tool.end());
reverse(tool.begin(), tool.end());
while(tim--){
count++;
if(tool.empty()) continue;
while(tim + tool.back() <= a){
tim += tool.back();
tool.pop_back();
}
if(tim == 1){
tim += min(tool.back(), a);
tool.pop_back();
}
}
cout << count-1 << endl;
}
int main() {
// your code goes here
ll t;
cin>>t;
while(t--){
solve();
}
return 0;
}