QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#482#277074#7678. The Gameucup-team1785Yu_JieFailed.2023-12-06 17:44:032023-12-06 17:44:04

Details

Extra Test:

Invalid Input

input:

1
300000 100000
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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:


result:

FAIL Expected integer, but "1e+091e+091e+091e+091e+091e+09...91e+091e+091e+091e+091e+091e+09" found (test case 1, stdin, line 4)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#277074#7678. The GameYu_JieAC ✓124ms34484kbC++141.3kb2023-12-06 15:08:582023-12-06 15:08:58

answer

#include<bits/stdc++.h>
using namespace std;
const int N=300005;
int n,m,a[N],b[N];
int read() {
	int x=0,f=1; char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-48;
	return x*f;
}
void solve() {
    n=read(); m=read();
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1;i<=m;i++) b[i]=read();
    sort(a+1,a+n+1,[](int x,int y){return x>y;});
    sort(b+1,b+m+1,[](int x,int y){return x>y;});
    int x=0;
    for(int i=1;i<=m;i++) {
        if(a[i]>b[i]) {puts("-1"); return ;}
        x+=b[i]-a[i];
    }
    if(x>n-m) {puts("-1"); return ;}
    x=n-m-x;
    multiset<int> s,o;
    vector<int> ans;
    for(int i=1;i<=n;i++) s.insert(a[i]);
    for(int i=1;i<=m;i++) for(int j=a[i];j<b[i];j++) o.insert(j);
    while(x) {
        int v=*s.begin();
        ans.push_back(v);
        s.erase(s.begin());
        s.insert(v+1);
        s.erase(s.begin());
        if(o.find(v)!=o.end()) o.erase(o.find(v));
        else {
            x--;
            if(v==b[m]) {puts("-1"); return ;}
        }
    }
    for(int i:o) ans.push_back(i);
    printf("%d\n",ans.size());
    for(int i:ans) printf("%d ",i); puts("");
}
int main() {
    for(int T=read();T--;) solve();
    return 0;
}