Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- //#include <bits/stdc++.h>
- #define pii pair <int,int>
- #define mii map<int,int>
- #define pq priority_queue
- using namespace std;
- using ll = long long;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n\n";
- }
- int inf = 2e9 + 10;
- int t,n,k;
- void go(pq <pii, vector <pii>, greater<pii>> &A, pq <pii, vector <pii>, greater<pii>> &B, ll &way){
- int dst = 0;
- while (!A.empty()){
- cout<<"GO\n";
- cout<<A.top().first<<' '<<A.top().second<<'\n';
- int pz = k;//порция коробок на проход
- while (pz > 0 && !A.empty()){
- dst = max(dst, A.top().first);
- while (A.top().second > 0 && pz > 0){
- A.top().second--;
- pz--;
- cout<<"pz= "<<pz<<"\n";
- }
- if (A.top().second == 0) A.pop();
- }
- if (A.empty()){
- way += dst;
- if (!B.empty()) way += dst;
- }
- else way += dst * 2;
- }
- }
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- auto cmp = [](pii l, pii r) {return abs(l.first) > abs(r.second);};
- cin>>t;
- for (int q=0;q<t;++q){
- cin>>n>>k;
- int tt = n;
- mii crd;
- int mxL=-1,mxR=-1;
- for (int i = 0;i<n;++i){
- int x;
- cin>>x;
- crd[x]++;
- if (x < 0){
- mxL = max(x, mxL);
- }else mxR = max(mxR, x);
- }
- pq <pii, vector <pii>, greater<pii>> L;
- pq <pii, vector <pii>, greater<pii>> R;
- for (auto y: crd){
- if (y.first < 0)
- {
- L.push({abs(y.first), y.second});
- }
- else {
- R.push(y);
- }
- }
- ll way = 0;
- if (mxL > mxR){//начнём с R
- go(R, L, way);
- go(L, R, way);
- }
- else{
- go(L, R, way);
- go(R, L, way);
- }
- cout<<"way= "<<way<<"\n";
- }
- }
- /*
- 1
- 4 2
- 1000000000 1000000000 1000000000 1000000000
- */
Add Comment
Please, Sign In to add comment