fork download
  1. #include <bits/stdc++.h>
  2. //#include <ext/pb_ds/assoc_container.hpp>
  3. //#include <ext/pb_ds/tree_policy.hpp>
  4. #define ll long long
  5. #define ld long double
  6. #define ff first
  7. #define ss second
  8. #define pii pair<int,int>
  9. #define pll pair<long long, long long>
  10. #define vi vector<int>
  11. #define vl vector<long long>
  12. #define pb push_back
  13. #define rep(i, b) for(int i = 0; i < (b); ++i)
  14. #define rep2(i,a,b) for(int i = a; i <= (b); ++i)
  15. #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
  16. #define count_bits(x) __builtin_popcountll((x))
  17. #define all(x) (x).begin(),(x).end()
  18. #define siz(x) (int)(x).size()
  19. #define forall(it,x) for(auto& it:(x))
  20. //using namespace __gnu_pbds;
  21. using namespace std;
  22. //typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
  23. //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
  24. //ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
  25. const int INF = 1e9+50;
  26. const ll INF_L = 1e18+40;
  27. const ll MOD = 1e9+7;
  28.  
  29.  
  30. void solve()
  31. {
  32. int n;
  33. cin >> n;
  34. vl D(n);
  35. vl A(n);
  36. vl B(n);
  37. rep(i,n) cin >> D[i];
  38. rep(i,n) cin >> A[i];
  39. rep(i,n) cin >> B[i];
  40. ll ans = 0;
  41. ll p,k;
  42. cin >> p >> k;
  43. rep(mask,(1 << n))
  44. {
  45. ll a = p;
  46. ll b = k;
  47. rep(i,n)
  48. {
  49. if(mask & (1 << i))
  50. {
  51. a += D[i];
  52. b += D[i];
  53. b = min(b,B[i]);
  54. }
  55. else
  56. {
  57. a += D[i];
  58. b += D[i];
  59. a = min(a,A[i]);
  60. }
  61. }
  62. ans = max(ans,a+b);
  63. }
  64. cout << ans << "\n";
  65. }
  66.  
  67. int main()
  68. {
  69. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  70. //random();
  71. int t = 1;
  72. //cin >> t;
  73. while(t--) solve();
  74. }
Success #stdin #stdout 0.01s 5284KB
stdin
7
6 0 7 4 2 8 0
3 8 0 3 8 5 0
6 7 7 5 7 0 6
9 8
stdout
36