fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define dd double
  5. #define ld long double
  6. #define ull unsigned long long
  7. #define yes cout << "YES\n"
  8. #define no cout << "NO\n"
  9. #define el "\n"
  10. #define Arwa ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  11. #define fix(x) cout << fixed << setprecision(x)
  12. #define all(v) v.begin(),v.end()
  13. #define dpp(v,val) memset(v,val,sizeof(v))
  14. #define mod 1e9+7
  15. #define oo 1e9
  16. const int N = 1e5 + 5;
  17. int c,n1,n2,n3;
  18. int solve(int c,int n1,int n2,int n3)
  19. {
  20. if(c<=0)
  21. return 0;
  22. int t1=oo,t2=oo,t3=oo;
  23. if(n3>0)
  24. t1=solve(c-8,n1+2,n2,n3-1)+1;
  25. if(n2>0)
  26. t2=solve(c-5,n1,n2-1,n3)+1;
  27. if(n1>0)
  28. t3=solve(c-1,n1-1,n2,n3)+1;
  29. return min({t1,t2,t3});
  30. }
  31. void HereWeGoAgain()
  32. {
  33. cin>>c>>n1>>n2>>n3;
  34. c=c*8;
  35. cout<<solve(c,n1,n2,n3)<<el;
  36. }
  37. int32_t main()
  38. {
  39. Arwa
  40. int t=1;
  41. cin>>t;
  42. for(int i=1;i<=t;i++)
  43. {
  44. HereWeGoAgain();
  45. }
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
0