-
Notifications
You must be signed in to change notification settings - Fork 16
/
NOCHANGE
72 lines (66 loc) · 1.64 KB
/
NOCHANGE
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
#include <stdio.h>
int largest(long int arr[], int n)
{
int i;
int max = arr[0];
for (i = 1; i < n; i++)
if (arr[i] > max)
max = arr[i];
return max;
}
int main(void) {
int t,i,j,z,g,h;
scanf("%d",&t);
for(i=0; i<t; i++){
int n,p,x=0,flag=0,flag2=0;
scanf("%d",&n);
scanf("%d",&p);
long int coins[n],A[n],b;
for(j=0; j<n; j++){
scanf("%ld",&coins[j]);
}
b=largest(coins,n);
for(j=n-1; j>0; j--){
if(b%coins[j]!=0){A[x]=coins[j]; x++;}
}
x=0;
for(j=0; j<n; j++){
if(p%coins[j]!=0){ flag=1; break;}
}
if(flag==1){
for(j=0; j<n; j++){
if(p%coins[j]!=0){coins[j]=((p-(p%coins[j]))/coins[j])+1; flag2=1; break; }else{coins[j]=0;}
x++;
}
if(flag2==1){
for(j=x+1; j<n; j++){coins[j]=0;}
}
}
int s=0;
if(flag!=1){
for(j=0; j<n; j++){
for(z=j; z<n; z++){
if(coins[j]>coins[z]){
if(coins[j]%coins[z]!=0){coins[z]=((coins[j])/coins[z])+1; coins[j]=(p/coins[j])-1; flag=1; g=j; h=z; s=1;}
if(s==1){break;}
}else{
if(coins[z]%coins[j]!=0){coins[j]=((coins[z])/coins[j])+1; coins[z]=(p/coins[z])-1; flag=1; g=j; h=z; s=1;}
if(s==1){break;}
}
}
}
for(j=0; j<n; j++){
if(j!=g && j!=h){coins[j]=0;}
}
}
if(flag==0){
printf("NO\n");}
if(flag==1){
printf("YES ");
for(j=0; j<n; j++){
printf("%ld ",coins[j]);
}
printf("\n"); }
}
return 0;
}