QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#241224#7678. The Gameucup-team1134#WA 1ms3460kbC++172.3kb2023-11-06 00:38:122023-11-06 00:38:13

Judging History

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

  • [2023-11-06 00:38:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3460kb
  • [2023-11-06 00:38:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

bool check(vector<ll> A,vector<ll> B,vector<ll> ans){
    multiset<ll> MS;
    for(ll x:A) MS.insert(x);
    for(ll x:ans){
        if(MS.find(x)==MS.end()) return false;
        MS.erase(MS.find(x));
        MS.insert(x+1);
        MS.erase(MS.begin());
    }
    vector<ll> C;
    for(ll x:MS) C.push_back(x);
    return (B==C);
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        ll N,M;cin>>N>>M;
        vector<ll> A(N),B(M);
        for(int i=0;i<N;i++) cin>>A[i];
        for(int i=0;i<M;i++) cin>>B[i];
        sort(all(A));
        sort(all(B));
        
        ll ba=0;
        for(int i=0;i<M;i++){
            if(A[N-1-i]>B[M-1-i]){
                ba=-1;
                break;
            }
            ba+=B[M-1-i]-A[N-1-i];
        }
        if(ba==-1||ba>N-M) cout<<-1<<"\n";
        else{
            ll mu=N-M-ba;
            multiset<ll> MS;
            for(ll x:A) MS.insert(x);
            vector<ll> ans;
            
            for(int t=0;t<mu;t++){
                ll x=*MS.begin();MS.erase(MS.find(x));
                ans.push_back(x);
                MS.insert(x+1);
                MS.erase(MS.begin());
            }
            
            vector<ll> C;
            for(ll x:MS) C.push_back(x);
            
            vector<ll> ad;
            for(int i=0;i<M;i++){
                for(ll j=C[N-1-i];j<B[M-1-i];j++) ad.push_back(j);
            }
            
            sort(all(ad));
            
            for(ll x:ad) ans.push_back(x);
            
            if(check(A,B,ans)){
                cout<<si(ans)<<"\n";
                for(ll x:ans) cout<<x<<" ";
                cout<<"\n";
            }else{
                cout<<-1<<"\n";
            }
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3460kb

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:

-1
-1
-1
-1
-1
-1

result:

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