QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395553#7678. The Gamezzuqy#RE 0ms8036kbC++144.0kb2024-04-21 16:13:242024-04-21 16:13:24

Judging History

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

  • [2024-04-21 16:13:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:8036kb
  • [2024-04-21 16:13:24]
  • 提交

answer

#include<bits/stdc++.h>
#include<iomanip>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<deque>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<stack>
#include<algorithm>
#include<vector>
#include<cctype>
#include<utility>
#include<set>
#include<bitset>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define inf 100000000000000000ll
#define ldb long double
#define pb push_back
#define put_(x) printf("%d ",x)
#define putl_(x) printf("%lld ",x)
#define get(x) x=read()
#define putl(x) printf("%lld\n",x)
#define rep(p,n,i) for(int i=p;i<=n;i+=1)
#define fep(n,p,i) for(int i=n;i>=p;--i)
#define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define pii pair<int,int>
#define mk make_pair
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define uint unsigned long long
#define ui unsigned
#define sq sqrt	
#define x(w) t[w].x
#define r(w) t[w].r
#define l(w) t[w].l
#define yy p<<1|1
#define zz p<<1
#define sum(w) t[w].sum
#define mod 1000000007
#define sc(A) scanf("%d",&A)
#define scl(A) scanf("%lld",&A)	
#define scs(A) scanf("%s",A)
#define put(A) printf("%d\n",A)
#define min(x,y) (x>=y?y:x)
#define max(x,y) (x>=y?x:y)
#define sub(x,y) (x-y<0?x-y+mod:x-y)
using namespace std;
const int MAXN=300010<<1;
int T;
int m,n;
int a[MAXN],b[MAXN];
int q[MAXN],L;
int cmp(int x,int y){return x>y;}
multiset<int>s;
void SC()
{
    rep(1,m,i)
    {
        int x=*s.rbegin();
        auto it=s.find(x);
        a[i]=*it;
        s.erase(it);
    }
    s.clear();
    rep(1,m,i)
    {
        while(a[i]<b[i])
        q[++L]=a[i],++a[i];
    }
}

int main()
{
    //freopen("1.in","r",stdin);
    sc(T);
    while(T--)
    {
        sc(n);sc(m);
        rep(1,n,i)sc(a[i]);
        rep(1,m,i)sc(b[i]);
        sort(a+1,a+1+n,cmp);
        sort(b+1,b+1+m,cmp);
        int res=n-m;ll sum=0;
        L=0;int flag=0;
        s.clear();
        rep(1,m,i)
        {
            if(a[i]>b[i])flag=1;
            else sum+=b[i]-a[i];
        }
        if(flag)
        {
            put(-1);
            continue;
        }
        if(sum>res)
        {
            put(-1);
            continue;
        }
        rep(1,n,i)s.insert(a[i]);
        while(1)
        {
            auto it=s.begin();
            int x=*it;
            if(x==b[m])
            {
                flag=1;
                break;
            }
            int cnt=0;
            while(x==*it)
            {
                ++cnt;
                s.erase(it);
                it=s.begin();
            }
            int CC=max(0,m-(int)s.size());
            if(CC==0)
            {
                while(1)
                {
                    if(sum==s.size()-m+cnt)
                    {
                        SC();
                        goto mark;
                    }
                    if(!cnt)break;
                    else 
                    {
                        --cnt;q[++L]=x;
                        if(cnt)s.insert(x+1),--cnt;
                    }
                }
            }
            else
            {
                while(1)
                {
                    if(sum==s.size()-m+cnt)
                    {
                        SC();
                        goto mark;
                    }
                    if(!cnt)break;
                    else
                    {
                        --cnt;
                        q[++L]=x;
                        if(CC)--sum,--CC,s.insert(x+1),--cnt;
                        else
                        {        
                            if(cnt)s.insert(x+1),--cnt;
                        }
                    }
                }
            }
        }
        if(flag)
        {
            put(-1);
            continue;
        }
        mark:
        put(L);
        rep(1,L,i)put_(q[i]);
        puts("");
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 8036kb

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:

2
1 3 
-1
3
2 4 4 
5
1 1 1 2 3 
2
1 1 
-1

result:

ok ok (6 test cases)

Test #2:

score: -100
Runtime Error

input:

7056
4 3
1 1 1 1
1 1 1
4 3
1 1 1 1
1 1 2
4 3
1 1 1 1
1 1 3
4 3
1 1 1 1
1 1 4
4 3
1 1 1 1
1 1 5
4 3
1 1 1 1
1 1 6
4 3
1 1 1 1
1 2 2
4 3
1 1 1 1
1 2 3
4 3
1 1 1 1
1 2 4
4 3
1 1 1 1
1 2 5
4 3
1 1 1 1
1 2 6
4 3
1 1 1 1
1 3 3
4 3
1 1 1 1
1 3 4
4 3
1 1 1 1
1 3 5
4 3
1 1 1 1
1 3 6
4 3
1 1 1 1
1 4 4
4 3
1 1...

output:


result: