sacgajcvs

Untitled

Jul 27th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. /*
  2. 7
  3. 5 6 9 11 12 16 20
  4. 2 3 1 5 3 1 1
  5.  
  6. _____ _ _ _ _
  7. |_ _| |__ ___ / \ _ __ ___| |__ _ _| |
  8. | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  9. | | | | | | __// ___ \| | | \__ \ | | | |_| | |
  10. |_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
  11.  
  12. */
  13. #include<bits/stdc++.h>
  14. #define ll long long
  15. #define pb push_back
  16. #define ppb pop_back
  17. #define endl '\n'
  18. #define mii map<ll int,ll int>
  19. #define msi map<string,ll int>
  20. #define mis map<ll int, string>
  21. #define rep(i,a,b) for(ll int i=a;i<b;i++)
  22. #define mpi map<pair<ll int,ll int>,ll int>
  23. #define pii pair<ll int,ll int>
  24. #define vi vector<ll int>
  25. #define vii vector<pair<ll int, ll int>>
  26. #define vs vector<string>
  27. #define all(a) (a).begin(),(a).end()
  28. #define F first
  29. #define S second
  30. #define sz(x) (ll int)x.size()
  31. #define hell 1000000007
  32. #define lbnd lower_bound
  33. #define ubnd upper_bound
  34. #define bs binary_search
  35. #define mp make_pair
  36. #define what_is(x) cerr << #x << " is " << x << endl;
  37. #define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  38. using namespace std;
  39. #define N 100005
  40.  
  41. void solve()
  42. {
  43. ll n;
  44. cin>>n;
  45. vi a(n),b(n);
  46. rep(i,0,n)
  47. {
  48. cin>>a[i];
  49. }
  50. rep(i,0,n)
  51. {
  52. cin>>b[i];
  53. }
  54. stack<pii>st;
  55. st.push({0,b[0]+a[0]});
  56. vi ans(n,-1);
  57. rep(i,1,n)
  58. {
  59. if(st.top().S>=a[i])
  60. {
  61. pii tmp = st.top();
  62. st.pop();
  63. if(i!=n-1 && a[i]+b[i]<a[i+1])
  64. ans[i]=a[i]+b[i];
  65. tmp.S=max(tmp.S,a[i]+b[i]);
  66. st.push(tmp);
  67. }
  68. else
  69. {
  70. if(i!=n-1 && a[i]+b[i]<a[i+1])
  71. ans[i]=a[i]+b[i];
  72. else
  73. st.push({i,a[i]+b[i]});
  74. }
  75. }
  76. // while(!st.empty())
  77. // {
  78. // cout<<st.top().F<<" "<<st.top().S<<endl;
  79. // st.pop();
  80. // }
  81. for(ll i=n-1;i>=0;i--)
  82. {
  83. if(ans[i]==-1)
  84. ans[i]=st.top().S;
  85. if(st.top().F==i)
  86. {
  87. st.pop();
  88. }
  89. }
  90. rep(i,0,n)
  91. cout<<ans[i]<<" ";
  92. return;
  93. }
  94. int main()
  95. {
  96. ios_base::sync_with_stdio(false);
  97. cin.tie(0);
  98. cout.tie(0);
  99. int TESTS=1;
  100. // cin>>TESTS;
  101. while(TESTS--)
  102. {
  103. solve();
  104. }
  105. time
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment