- 了解了goto语句的用法。传言goto被视为“洪水猛兽”,但在OI中它是否真的没有可取之处呢
#include <bits/stdc++.h>
using namespace std;
int a[200005],b[200005];
long long s[200005];
int n,m;
int K(int n,int m)
{int kmax=0;while(n>0&&m>0&&n+m>2){if(n<m){swap(n,m);}n-=2;m-=1;kmax++;}return kmax;
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);int T;cin>>T;while(T--){cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+n+1);for(int i=1;i<=m;i++){cin>>b[i];}sort(b+1,b+m+1);int kmax=K(n,m);cout<<kmax<<"\n";int p=0,q=0;for(int i=1;i<=kmax;i++){s[i]=s[i-1];label:if(n-2*p-q>1&&m-p-2*q>1){if(a[n-p]-a[p+1]>b[m-q]-b[q+1]){s[i]=s[i]+a[n-p]-a[p+1];p++;}else{s[i]=s[i]+b[m-q]-b[q+1];q++;}}else if(n-2*p-q>1&&m-p-2*q>0){s[i]=s[i]+a[n-p]-a[p+1];p++;}else if(n-2*p-q>0&&m-p-2*q>1){s[i]=s[i]+b[m-q]-b[q+1];q++;}else if(n-2*p-q>1){q--;s[i]=s[i]-(b[m-q]-b[q+1]);s[i]=s[i]+a[n-p]-a[p+1];p++;goto label;}else{p--;s[i]=s[i]-(a[n-p]-a[p+1]);s[i]=s[i]+b[m-q]-b[q+1];q++;goto label; }cout<<s[i]<<" ";}if(kmax){cout<<"\n";}}return 0;
}