-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path71432307.cpp
59 lines (58 loc) · 945 Bytes
/
71432307.cpp
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
/*
ID: dahaeeh1
TASK: ariprog
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
void func()
{
int n,d;
cin>>n>>d;
int res=0;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
sort(arr,arr+n);
while(d)
{
if(arr[n-1]<d/2.0)
{
res+=d/arr[n-1]-1;
d-= ( d/arr[n-1]-1 )*arr[n-1];
//cout<<res<<" "<<d<<endl;
}
else
{
bool flag=false;
for(int i=0;i<n;i++)
if(arr[i]==d) flag=true;
if(flag)
{
res+=1;
break;
}
else
{
res+=2;
break;
}
}
}
cout<<res<<endl;
}
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
func();
}
return 0;
}