QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#264926#7678. The Gameqkm66666#RE 0ms0kbC++142.9kb2023-11-25 16:02:332023-11-25 16:02:34

Judging History

你现在查看的是最新测评结果

  • [2023-11-25 16:02:34]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-25 16:02:33]
  • 提交

answer

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<cstdio>
#include<cctype>
#include<vector>
#include<bitset>
#include<random>
#include<ctime>
#include<queue>
#include<cmath>
#include<list>
#include<map>
#include<set>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long,long long>
#define FF fflush(stdout)
#define inf 0x3f3f3f3f
#define endl "\n"
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//char buf[1<<20],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline int read()
{
    int s=0,f=1;
    char x=getchar();
    while(!isdigit(x))f=(x=='-'?-1:1),x=getchar();
    while(isdigit(x))s=s*10+x-'0',x=getchar();
    return s*f;
}
const int p=1e9+7;
//ll ksm(int a,int b){ll ans=1,bs=a;while(b){if(b&1)ans=ans*bs%p;bs=bs*bs%p;b>>=1;}return ans;}
mt19937 rd(time(0));
#define reaD read
int a[300005],b[300005];
multiset<int> S;
vector<int> ans;
int main()
{
    int T=reaD();
    while(T--)
    {
        int n=reaD(),m=reaD();
        for(int i=1;i<=n;i++)
        a[i]=read();
        sort(a+1,a+n+1);
        for(int i=1;i<=m;i++)
        b[i]=read();
        sort(b+1,b+m+1);
        bool ok=1;
        int s=0;
        for(int i=n-m+1;i<=n;i++)
        {
            if(a[i]>b[i-(n-m)])ok=0;
            s+=b[i-(n-m)]-a[i];
        }
        if(s>n-m)ok=0;
        if(!ok)
        {
            puts("-1");
            continue;
        }
        int xh=(n-m)-s;
        //cout<<xh;
        int up=a[n-m+1];
        for(int i=1;i<=n-m;i++)
        S.insert(a[i]);
        while(S.size()&&xh)
        {
            int x=*S.begin();//cout<<x;
            while(x==up)
            {
                if(a[n-m+1]==b[1])
                {
                    //puts("?");
                    ok=0;
                    break;
                }
                ans.pb(up);
                a[n-m+1]++;up++;
                S.erase(S.begin());
                if(!S.size())
                {//cout<<xh;
                    ok=0;
                    break;
                }
                // cout<<up;
                x=*S.begin();
            }
            if(!ok)break;
            ans.pb(x);
            xh--;
            S.erase(S.begin());
            S.insert(x+1);
            S.erase(S.begin());
        }
        S.clear();
        if(xh>0)puts("-1");
        else
        {
            for(int i=n-m+1;i<=n;i++)
            {
                for(int j=a[i];j<b[i-(n-m)];j++)
                ans.pb(j);
            }
            printf("%d\n",ans.size());
            for(auto i:ans)
            printf("%d ",i);
            puts("");
        }
        ans.clear();
    }
    system("pause");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

6
5 3
1 2 2 3 3
2 3 4
4 2
1 2 2 4
2 4
5 2
2 3 3 4 4
5 5
6 1
1 1 1 1 1 1
4
4 2
1 1 1 2
2 2
4 1
1 1 1 1
2

output:


result: