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 dp[1300][101][51];
  19. int solve(int c,int n1,int n2,int n3)
  20. {
  21. if(c<=0)
  22. return 0;
  23. int &ret=dp[c][n2][n3];
  24. if(ret!=-1) return ret;
  25. int t1=oo,t2=oo,t3=oo;
  26. if(n3>=1)
  27. t1=solve(c-1,n1+2,n2,n3-1)+1;
  28. if(n2>=2)
  29. t2=solve(c-1,n1,n2-2,n3)+2;
  30. if(n2>=1&&n1>=3)
  31. t2=solve(c-1,n1-3,n2-1,n3)+4;
  32. if(n1>=8)
  33. t3=solve(c-1,n1-8,n2,n3)+8;
  34. return min({t1,t2,t3});
  35. }
  36. void HereWeGoAgain()
  37. {
  38. cin>>c>>n1>>n2>>n3;
  39. dpp(dp,-1);
  40. cout<<solve(c,n1,n2,n3)<<el;
  41. }
  42. int32_t main()
  43. {
  44. Arwa
  45. int t=1;
  46. cin>>t;
  47. for(int i=1;i<=t;i++)
  48. {
  49. HereWeGoAgain();
  50. }
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0.01s 55908KB
stdin
Standard input is empty
stdout
0