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+2,1e18);
  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 p,k;
  41. cin >> p >> k;
  42. ll cur_sum = 0;
  43. rep(i,n)
  44. {
  45. cur_sum += D[i];
  46. A[i] -= cur_sum;
  47. B[i] -= cur_sum;
  48. }
  49. set<pll> minA;
  50. set<pll> minB;
  51. rep(i,n)
  52. {
  53. // cout << A[i] << " " << B[i] << " AB\n";
  54. //minA.insert({A[i],i});
  55. minB.insert({B[i],i});
  56. }
  57. ll ans = -1e18;
  58. minB.insert({k,n});
  59. minB.insert({-cur_sum,n+1});
  60. forall(it,minB)
  61. {
  62. if(it.ff > k) break;
  63. int ind = it.ss;
  64. //cout << it.ff << " " << min(k,it.ff) + min(p,(*minA.begin()).ff) << " ans\n";
  65. ans = max(ans,min(k,it.ff) + min(p,(*minA.begin()).ff));
  66. minA.insert({A[ind],ind});
  67.  
  68. }
  69. cout << ans + cur_sum*2 << "\n";
  70. }
  71.  
  72. int main()
  73. {
  74. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  75. //random();
  76. int t = 1;
  77. //cin >> t;
  78. while(t--) solve();
  79. }
Success #stdin #stdout 0.01s 5280KB
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
35