fork(1) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890123456789LL
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-8
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. #define dbl long double
  28. using namespace std;
  29. // mylittledoge
  30.  
  31. int main() {
  32. cin.sync_with_stdio(0);
  33. cin.tie(0);
  34. int T;
  35. cin >> T;
  36. for(int t =0; t < T; t++) {
  37. int N,K;
  38. cin >> N >> K;
  39. vector<int> C(N);
  40. for(int i =0; i < N; i++) cin >> C[i];
  41. vector<int> D(3601,1000000);
  42. priority_queue< pair<int,int>, vector< pair<int,int> >, greater< pair<int,int> > > q;
  43. q.push(make_pair(0,0));
  44. D[0] =0;
  45. while(!q.empty()) {
  46. pair<int,int> p =q.top();
  47. q.pop();
  48. if(p.ff != D[p.ss]) continue;
  49. for(int i =0; i < N; i++) if(D[max(0,min(3600,p.ss+C[i]))] > p.ff+1) {
  50. D[max(0,min(3600,p.ss+C[i]))] =p.ff+1;
  51. q.push(make_pair(D[max(0,min(3600,p.ss+C[i]))],max(0,min(3600,p.ss+C[i]))));}
  52. }
  53. for(int i =K; i <= 3600; i++) if(D[i] < 1000000) {
  54. cout << D[i] << " " << i-K << "\n";
  55. break;}
  56. }
  57. return 0;}
  58.  
  59. // look at my code
  60. // my code is amazing
Success #stdin #stdout 0s 3436KB
stdin
2
3 50
-10 10 60
1 50
20
stdout
2 0
3 10