fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int t;cin >> t;
  7. while(t--)
  8. {
  9. int n,p;cin >> n >> p;
  10. //cout << n << " " << p << endl;
  11. int arr[n];
  12.  
  13. vector< pair <int,int> > v,v1,v2;
  14.  
  15. for(int i = 0;i<n;i++){
  16. cin >> arr[i] ;
  17. // cout << arr[i] << endl;
  18. if(arr[i] != 1 && p%arr[i] == 0)
  19. {
  20. // cout << " uu" << endl;
  21. v.push_back(make_pair(arr[i],i));
  22. // cout << v[0].first << endl;
  23. }
  24. else if(arr[i] != 1 && p%arr[i] != 0){
  25. v1.push_back(make_pair(arr[i],i));
  26. //v2.push_back(arr[i]);
  27. }
  28. }
  29. // cout << "JJ" << endl;
  30. // cout << "dD" << v[0].first << endl;
  31. sort(v.begin(),v.end());
  32.  
  33. // cout << v[0].first << endl;
  34. vector<int> q(n,0);
  35. //cout << " V size " << v.size() << endl;
  36. //cout << v1[0].second << " v1[0]" << endl;
  37. bool t = false;
  38. if(v1.size() >= 1)
  39. {
  40. t = true;
  41. cout << "YES ";
  42. if(v1[0].first != 0)
  43. q[v1[0].second] = p/v1[0].first + 1;
  44. //for(int i = 0;i<q.size();i++){
  45. // cout << q[i] << " ";
  46.  
  47. //}
  48.  
  49. }
  50. else if(v.size() >=2 )
  51. {
  52.  
  53. int cp = 0;
  54. int i = 0;
  55. for(i = 1;i<v.size();i++){
  56. // cout << v[i].first << endl;
  57. if(v[i-1].first != 0)
  58. if(v[i].first % v[i-1].first != 0){
  59. cp++;
  60.  
  61. break;
  62. }
  63.  
  64. }
  65. // int x = (p/v[i-1].first) - 1;
  66. //int y = v[i-1].first*x + v[i].first;
  67. q[v[i].second] = (p/v[i].first) - 1;
  68. //cout << q[v[i].second] << endl;
  69. int x = p - q[v[i].second]*v[i].first;
  70. // cout << "x is " << x << endl;
  71. q[v[i-1].second] = x/v[i-1].first + 1;
  72.  
  73. // cout <<"ZZ" << endl;
  74. if(cp == 0)
  75. {cout << "NO" << endl;
  76. }
  77. else{
  78. t = true;
  79. cout << "YES " ;
  80. // for(int i = 0;i<q.size();i++){
  81. // cout << q[i] << " ";
  82. // }
  83. // cout << endl;
  84. }
  85. }
  86. else{
  87. //if(v.size() == 1)
  88. cout << "NO" << endl;
  89.  
  90. }
  91. if(t){
  92. for(int i = 0;i<q.size();i++){
  93. cout << q[i] << " ";
  94. }
  95. cout << endl;
  96. }
  97.  
  98.  
  99.  
  100.  
  101. }
  102. return 0;
  103. }
Success #stdin #stdout 0s 4276KB
stdin
5
2 10
1 5
2 4
1 5
3 25
3 5 10
3 39
3 13 39
3 12
2 4 6
stdout
NO
YES 0 1 
YES 9 0 0 
YES 5 2 0 
YES 0 2 1