fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24.  
  25. vector<int> boxes;
  26. vector<int> unitPerBox;
  27.  
  28. int consistency(int n, int t) {
  29.  
  30. vector<pair<int,int>> p;
  31. for(int i=0; i<n; i++){
  32. p.push_back({unitPerBox[i], boxes[i]});
  33. }
  34.  
  35. sort(begin(p), end(p), greater<pair<int,int>>());
  36.  
  37. int ans = 0;
  38. for(int i=0; i<n; i++){
  39. if(t==0) break;
  40. int units = p[i].first;
  41. int totalBox = p[i].second;
  42.  
  43. if(t < totalBox ){
  44. ans += t*units;
  45. t = 0;
  46. }
  47. else{
  48. ans += totalBox*units;
  49. t -= totalBox;
  50. }
  51. }
  52.  
  53. return ans;
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. int practice(int n, int t) {
  71.  
  72. return 0;
  73. }
  74.  
  75.  
  76. void solve() {
  77.  
  78. int n, t;
  79. cin >> n >> t;
  80.  
  81. boxes.resize(n);
  82. unitPerBox.resize(n);
  83. for(int i=0; i<n; i++) cin >> boxes[i];
  84. for(int i=0; i<n; i++) cin >> unitPerBox[i];
  85.  
  86. cout << consistency(n, t) << endl;
  87. // cout << consistency(n, t) << " -> " << practice(n, t) << endl;
  88.  
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95. int32_t main() {
  96. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  97.  
  98. int t = 1;
  99. cin >> t;
  100. while (t--) {
  101. solve();
  102. }
  103.  
  104. return 0;
  105. }
Success #stdin #stdout 0s 5324KB
stdin
2
3 3
1 2 3
3 2 1
3 6
3 1 6
2 7 4
stdout
7
27