QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#548868#7678. The GameFXLY_awaWA 3ms3712kbC++173.2kb2024-09-05 21:43:222024-09-05 21:43:23

Judging History

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

  • [2024-09-05 21:43:23]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3712kb
  • [2024-09-05 21:43:22]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long                               ll;
typedef unsigned long long                      ull;
// #define int                                     long long
#define itn                                     int
#define endl                                    '\n'
#define Endl                                    endl
#define ednl                                    endl
#define Ednl                                    endl
#define al(a)                                   (a).begin(),(a).end()
#define all(a)                                  (a).begin()+1,(a).end()
#define lowbit(x)                               (x&-x)
#define vi                                      vector<int>
#define pii                                     pair<int,int>
#define pb                                      push_back
#define fs                                      first
#define sc                                      second


constexpr long long maxlonglong = 9223372036854775807;   //9e18
constexpr int maxint = 2147483647;      //2e9
constexpr int INF = 0x7f7f7f7f; //2139062143
constexpr int M = 1e9 + 7;
constexpr int mod =  998244353;
constexpr int p = 0x1F351F35; // good hash number.
const double pi = acos(-1.0);

mt19937_64 rnd(time(0));
constexpr int N=1231564;
const int MAXN = 3e5+10;



inline void solve(){
    int n,m;cin>>n>>m;
    vi a(n+1),b(m+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>b[i];
    sort(all(a));sort(all(b));
    map<int,int> mp;int res=0;
    for(int i=1;i<=m;i++){
        mp[a[n-m+i]]++;
        int t=b[i]-a[n-m+i];
        if(t<0){
            cout<<-1<<endl;
            return;
        }
        res+=t;
    }
    priority_queue<int,vi,greater<int>> q;
    for(int i=1;i<=n;i++)q.push(a[i]);
    vi ans;
    while(q.top()<b[1]){
        int t=q.top();q.pop();
        if(mp.count(t)){
            res--;
            mp[t]--;
            mp[t+1]++;
            if(mp[t]==0)mp.erase(t);
        }
        ans.push_back(t);
        q.push(t+1);
        q.pop();
        if((int)q.size()-m==res){
            break;
        }
        if(q.empty()||q.top()==b[1]){
            cout<<-1<<endl;
            return;
        }
    }
    a.clear();
    a.push_back(0);
    if((int)q.size()-m!=res){
        cout<<-1<<endl;
        return;
    }
    while(q.size()){
        a.push_back(q.top());
        q.pop();
    }
    n=a.size()-1;
    int ra=n,rb=m;
    while(rb>0&&ra>0){
        for(int k=a[ra];k<b[rb];k++){
            ans.push_back(k);
        }
        ra--;rb--;
    }
    cout<<ans.size()<<Endl;
    for(auto i:ans){
        cout<<i<<" ";
    }
    cout<<endl;
}





signed main()
{
    //freopen("E:\work tool\code document\data\input.in", "r", stdin);
	//freopen("E:\work tool\code document\data\output.out", "w", stdout);
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);    //关闭同步  如果使用 则不要使用<cstdio>
    // cout << fixed << setprecision(10);
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Wrong Answer
time: 3ms
memory: 3712kb

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:

-1
1
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2 
-1
-1
-1
1
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer Jury has answer but participant has not (test case 1199)