Korotkodul

Tech9

Dec 12th, 2021 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. //#include <bits/stdc++.h>
  11. #define pii pair <int,int>
  12. #define mii map<int,int>
  13. #define pq priority_queue
  14. using namespace std;
  15. using ll = long long;
  16. void cv(vector <int> &v){
  17. for (auto x: v) cout<<x<<' ';
  18. cout<<"\n\n";
  19. }
  20. int inf = 2e9 + 10;
  21.  
  22.  
  23. int t,n,k;
  24.  
  25. void go(pq <pii, vector <pii>, greater<pii>> &A, pq <pii, vector <pii>, greater<pii>> &B, ll &way){
  26. int dst = 0;
  27. while (!A.empty()){
  28. cout<<"GO\n";
  29. cout<<A.top().first<<' '<<A.top().second<<'\n';
  30. int pz = k;//порция коробок на проход
  31. while (pz > 0 && !A.empty()){
  32. dst = max(dst, A.top().first);
  33. while (A.top().second > 0 && pz > 0){
  34.  
  35. A.top().second--;
  36. pz--;
  37. cout<<"pz= "<<pz<<"\n";
  38. }
  39. if (A.top().second == 0) A.pop();
  40. }
  41.  
  42. if (A.empty()){
  43. way += dst;
  44. if (!B.empty()) way += dst;
  45. }
  46. else way += dst * 2;
  47.  
  48. }
  49.  
  50.  
  51. }
  52.  
  53. int main()
  54. {
  55. /*ios::sync_with_stdio(0);
  56. cin.tie(0);
  57. cout.tie(0);*/
  58. auto cmp = [](pii l, pii r) {return abs(l.first) > abs(r.second);};
  59. cin>>t;
  60.  
  61. for (int q=0;q<t;++q){
  62. cin>>n>>k;
  63. int tt = n;
  64. mii crd;
  65. int mxL=-1,mxR=-1;
  66. for (int i = 0;i<n;++i){
  67. int x;
  68. cin>>x;
  69. crd[x]++;
  70. if (x < 0){
  71. mxL = max(x, mxL);
  72. }else mxR = max(mxR, x);
  73. }
  74. pq <pii, vector <pii>, greater<pii>> L;
  75. pq <pii, vector <pii>, greater<pii>> R;
  76. for (auto y: crd){
  77. if (y.first < 0)
  78. {
  79. L.push({abs(y.first), y.second});
  80. }
  81. else {
  82. R.push(y);
  83. }
  84. }
  85. ll way = 0;
  86. if (mxL > mxR){//начнём с R
  87. go(R, L, way);
  88. go(L, R, way);
  89. }
  90. else{
  91. go(L, R, way);
  92. go(R, L, way);
  93. }
  94. cout<<"way= "<<way<<"\n";
  95. }
  96. }
  97. /*
  98. 1
  99. 4 2
  100. 1000000000 1000000000 1000000000 1000000000
  101. */
  102.  
Add Comment
Please, Sign In to add comment