QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#548908#7678. The GameJiangnan01WA 0ms3820kbC++143.3kb2024-09-05 22:02:142024-09-05 22:02:14

Judging History

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

  • [2024-09-05 22:02:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3820kb
  • [2024-09-05 22:02:14]
  • 提交

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;
    int con=0;
    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(a[n-m+i]<=b[1])con++;
        if(b[i]==b[1])con--;
        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(con>0 || q.top()<b[1]){
        int t=q.top();q.pop();
        if(t==b[1])con--;
        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(q.size()-m==res){
            break;
        }
        if(q.top()==b[1]||q.empty()){
            cout<<-1<<endl;
            return;
        }
    }
    if(q.size()-m!=res)
    {
        cout<<-1<<endl;
        return;
    }
    a.clear();
    a.push_back(0);
    while(q.size()){
        a.push_back(q.top());
        q.pop();
    }
    n=a.size()-1;
    int ra=n,rb=m;
    while(rb>0){
        int tmp=b[rb]-a[ra];
        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;
    ans.clear();

    
    
    

}





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: 3820kb

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: 0ms
memory: 3616kb

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)