Advertisement
dakshdixit183

Chef and Time Machine Code

Aug 23rd, 2023
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. /*Daksh Dixit*/
  2. #pragma GCC optimize("O3,unroll-loops")
  3. #include<bits/stdc++.h>
  4. #include<ext/pb_ds/assoc_container.hpp>
  5. #include<ext/pb_ds/tree_policy.hpp>
  6.  
  7. using namespace std;
  8. using namespace chrono;
  9. using namespace __gnu_pbds;
  10.  
  11. #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  12. #define int long long
  13. #define mod0 1000000007
  14. #define mod1 998244353
  15. #define inf 1e18
  16. #define endl "\n"
  17. #define pb push_back
  18. #define ppb pop_back
  19. #define mp make_pair
  20. #define ff first
  21. #define ss second
  22. #define PI 3.141592653589793238462
  23. #define set_bits(x) __builtin_popcountll(x)
  24. #define sz(x) ((int)(x).size())
  25. #define all(x) (x).begin(), (x).end()
  26. #define print(x) cout<<x<<"\n"
  27. #define fr(i,a,b) for(int i = a; i < b; i++)
  28. #define ms(arr, v) memset(arr, v, sizeof(arr))
  29. #define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
  30. #define ain(a, lb, rb) for (int ele = lb; ele <= rb; ele++) cin >> a[ele];
  31. #define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
  32. #define aout(a, lb, rb) {for (int ele = (lb); ele <= (rb); ele++) { if (ele > (lb)) cout << " "; cout << a[ele]; } cout << '\n';}
  33. #define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
  34. #define readgraph(list, edges) for (int i = 0; i < edges; i++) {int a, b; cin >> a >> b; a--; b--; list[a].pb(b); list[b].pb(a);}
  35. #define has_bits(bit_mask, x) ((bit_mask) & (1ULL << (x)))
  36. #define turn_on_bit(bit_mask, x) (bit_mask |= (1ULL << (x)))
  37. #define turn_off_bit(bit_mask, x) (bit_mask &= (~( 1ULL << (x))))
  38. #define smallest_on_bit(bit_mask) (__builtin_ctzll(int)((bit_mask) & (~(bit_mask))))
  39. typedef unsigned long long ull;
  40. typedef long double lld;
  41. typedef pair<int,int> pi;
  42. typedef vector<int> vi;
  43. typedef vector<pi> vpi;
  44. typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
  45. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //greater<int> for descending set, also less_equal<int> which is ascending multiset
  46.  
  47. /*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
  48. //DEBUG
  49. #ifndef ONLINE_JUDGE
  50. #define debug(x) cerr << #x<<" = "; _print(x); cerr << endl;
  51. #else
  52. #define debug(x);
  53. #endif
  54. void _print(int t) {cerr << t;}
  55. void _print(string t) {cerr << t;}
  56. void _print(char t) {cerr << t;}
  57. void _print(lld t) {cerr << t;}
  58. void _print(double t) {cerr << t;}
  59. void _print(ull t) {cerr << t;}
  60.  
  61. template <class T, class V> void _print(pair <T, V> p);
  62. template <class T> void _print(vector <T> v);
  63. template <class T> void _print(set <T> v);
  64. template <class T, class V> void _print(map <T, V> v);
  65. template <class T> void _print(multiset <T> v);
  66. template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
  67. template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
  68. template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
  69. template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
  70. template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
  71. void _print(pbds v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
  72. void _print(ordered_set v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
  73. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  74.  
  75. /*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
  76. int MSB(int n){return 63-__builtin_clzll(n);}
  77. int getIthbit(int n, int i){return ( n & ( 1 << i) ) == 0 ? 0 : 1;}
  78. void setIthBit(int &n, int i){ n = n | (1 << i);}
  79. void clearIthBit(int &n, int i){ n = n & ( ~(1 << i));}
  80. int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
  81. int expo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
  82. void extendgcd(int a, int b, int*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); int x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
  83. int mminv(int a, int m){int arr[3];extendgcd(a, m, arr); if(arr[2]!=1){return -1;}arr[0] =(arr[0]%m + m)%m ;return arr[0];} //Modulo Inverse Exist only if gcd(a,m)=1;
  84. int mminvprime(int a, int m){int ans = expo(a, m - 2, m); ans = (ans%m+m)%m; return ans;} //If a,m are Coprime
  85. vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
  86. int phin(int n) {int number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (int i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
  87. bool revsort(int a, int b) {return a > b;}
  88. int combination(int n, int r, int m, int *fact, int *ifact) {int val1 = fact[n]; int val2 = ifact[n - r]; int val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
  89. void google(int t) {cout << "Case #" << t << ": ";}
  90. int mod_add(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
  91. int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
  92. int mod_sub(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
  93. int mod_div(int a, int b, int m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m
  94. int getRandomNumber(int l, int r) {return uniform_int_distribution<int>(l, r)(rng);}
  95. /*---------------------------------------------------------------------------------------------------------------------------------------------------------*/
  96.  
  97. #ifndef ONLINE_JUDGE
  98. const int N = 1e4+5;
  99. #else
  100. const int N = 1e6 + 585;
  101. #endif
  102.  
  103.  
  104. void solve(){
  105. int n,k,m; //k(white),m(black)
  106. cin>>n>>k>>m;
  107. vi a(n),b(n),c(k),d(m);
  108. ai(a,n);
  109. ai(b,n);
  110. multiset<int> st;
  111. fr(i,0,m+k){
  112. int x;
  113. cin>>x;
  114. st.insert(x);
  115. }
  116. fr(i,0,n){
  117. a[i]-=b[i];
  118. }
  119. int ans = 0;
  120. for(int i=0;i<n;i++){
  121. if(a[i]==0){
  122. continue;
  123. }
  124. if(lower_bound(st.rbegin(),st.rend(),a[i],greater<int>())==st.rend()){
  125. ans+=a[i];
  126. continue;
  127. }
  128. auto it = *lower_bound(st.rbegin(),st.rend(),a[i],greater<int>());
  129. ans+=(a[i]-it);
  130. st.erase(st.find(it));
  131. }
  132. cout<<ans<<endl;
  133.  
  134.  
  135. }
  136.  
  137. /*---------------------------------------------------------------------------------------------------------------------------------------------------------*/
  138. signed main(){
  139. fast;
  140. auto start1 = high_resolution_clock::now();
  141. int t=1;
  142. cin>>t;
  143. while(t--){
  144. solve();
  145. }
  146. auto stop1 = high_resolution_clock::now();
  147. auto duration = duration_cast<microseconds>(stop1 - start1);
  148. #ifndef ONLINE_JUDGE
  149. cerr << "Time: " << duration . count() / 1000 << endl;
  150. #endif
  151. return 0;
  152. }
  153. /*---------------------------------------------------------------------------------------------------------------------------------------------------------*/
  154.  
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement