sacgajcvs

Untitled

Oct 20th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. /*
  2. _____ _ _ _ _
  3. |_ _| |__ ___ / \ _ __ ___| |__ _ _| |
  4. | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  5. | | | | | | __// ___ \| | | \__ \ | | | |_| | |
  6. |_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
  7.  
  8. */
  9. #include<bits/stdc++.h>
  10. #include <ext/pb_ds/assoc_container.hpp>
  11. #include <ext/pb_ds/tree_policy.hpp>
  12. #define ll long long
  13. #define pb push_back
  14. #define ppb pop_back
  15. #define endl '\n'
  16. #define mii map<ll,ll>
  17. #define msi map<string,ll>
  18. #define mis map<ll, string>
  19. #define rep(i,a,b) for(ll i=a;i<b;i++)
  20. #define repr(i,a,b) for(ll i=b-1;i>=a;i--)
  21. #define trav(a, x) for(auto& a : x)
  22. #define pii pair<ll,ll>
  23. #define vi vector<ll>
  24. #define vii vector<pair<ll, ll>>
  25. #define vs vector<string>
  26. #define all(a) (a).begin(),(a).end()
  27. #define F first
  28. #define S second
  29. #define sz(x) (ll)x.size()
  30. #define hell 1000000007
  31. #define lbnd lower_bound
  32. #define ubnd upper_bound
  33. #define max(a,b) (a>b?a:b)
  34. #define min(a,b) (a<b?a:b)
  35.  
  36. /* For Debugging */
  37. #define DEBUG cerr<<"\n>>>I'm Here<<<\n"<<endl;
  38. #define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
  39. #define what_iss(x) cerr << #x << " = " << x << endl;
  40. #define what_is(x) cerr << #x << " = " << x << " ";
  41.  
  42. std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
  43. #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
  44. #define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  45. #define DECIMAL(n) cout << fixed ; cout << setprecision(n);
  46. #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  47. using namespace __gnu_pbds;
  48. using namespace std;
  49. #define PI 3.141592653589793
  50. #define N 100005
  51.  
  52. class Solution {
  53. public:
  54. vector<int> ma;
  55. int getValue(int vl) {
  56. // for(auto i:ma) {
  57. // cout << i << " ";
  58. // }
  59. // cout << endl;
  60. // what_iss(vl);
  61. return (int)(lower_bound(ma.begin(),ma.begin(), vl) - ma.begin());
  62. }
  63. int jobScheduling(vector<int>& a, vector<int>& b, vector<int>& c) {
  64. int n = a.size();
  65. for(int i = 0; i < n; i++) {
  66. ma.push_back(a[i]);
  67. ma.push_back(b[i]);
  68. }
  69. sort(ma.begin(),ma.end());
  70. ma.resize(unique(ma.begin(), ma.end())-ma.begin());
  71.  
  72. for(auto i:ma) {
  73. cout << i << " ";
  74. }
  75. cout << endl;
  76.  
  77. vector<int> dp(ma.size() + 5,0);
  78. vector<vector<int>> v(ma.size() + 5);
  79.  
  80. for(int i = 0; i < n; i++) {
  81. what_is(a[i]);
  82. what_iss(getValue(a[i]));
  83. v[getValue(a[i])].push_back(i);
  84. }
  85. // cout << ma.size() + 3 << endl;
  86. for(int i = ma.size() + 3; i >= 0; i--) {
  87. dp[i] = dp[i+1];
  88. for(auto j : v[i]) {
  89. what_is(i);
  90. what_is(j);
  91. what_iss(dp[i]);
  92. dp[i] = max(dp[i], c[j] + dp[getValue(b[j])]);
  93. }
  94. // what_is(i);
  95. // what_iss(dp[i]);
  96. }
  97. for(auto i:dp) {
  98. cout << i << " ";
  99. }
  100. cout << endl;
  101. return dp[0];
  102.  
  103. }
  104. };
  105.  
  106.  
  107. void solve()
  108. {
  109. ll n;
  110. cin >> n;
  111. vector<int> a(n),b(n),c(n);
  112. rep(i,0,n) {
  113. cin >> a[i];
  114. }
  115. rep(i,0,n) {
  116. cin >> b[i];
  117. }
  118. rep(i,0,n) {
  119. cin >> c[i];
  120. }
  121. Solution tmp;
  122. cout << tmp.jobScheduling(a,b,c) << endl;
  123. return;
  124. }
  125. int main()
  126. {
  127. FAST
  128. int TESTS=1;
  129. // cin>>TESTS;
  130. rep(i,0,TESTS)
  131. {
  132. // cout<<"Case #"<<i+1<<": ";
  133. solve();
  134. }
  135. // TIME
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment