QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666266#7678. The GameAshbourneWA 10ms3780kbC++201.5kb2024-10-22 17:27:032024-10-22 17:27:11

Judging History

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

  • [2024-10-22 17:27:11]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:3780kb
  • [2024-10-22 17:27:03]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
void solve(){
	// auto add = [&](int &x, int y)->void{
		// x += y;
	// };
	// auto check = [&]()->bool{
// 		
	// }
	cin >> n >> m;
	int sum1 = 0, sum2 = 0;
	map<int, int>mp;
	vector<int> a(n + 1), b(m + 1);
	for(int i = 1; i <= n; ++ i){
		int x; cin >> x;
		a[i] = x;
		mp[x]++;
	}
	for(int i = 1; i <= m; ++ i){
		cin >> b[i];
		sum1 += b[i];
	}
	sort(a.begin() + 1, a.begin() + n + 1);
	sort(b.begin() + 1, b.begin() + m + 1);
	for(int i = n - m + 1; i <= n; ++ i){
		sum2 += a[i];
	}
	int tt = sum1 - sum2;
	if(sum1 - sum2 > n - m || tt < 0){
		cout << -1 << endl; 
		return;
	}
	vector<int> ans;
	int cs = n - m - sum1 + sum2, u = 0;
	bool flag = 1;
	for(int i = 1; i <= cs; ++ i){
		// if(a[n - m + 1] > b[1]){
			// flag = 0;
			// break;
		// }
		auto [k, v] = *mp.begin();
		a[i + v - 1] ++;
		if(i + v - 1 >= n - m + 1) {
			cs++; tt--; 
			if(a[i + v - 1] > b[i + v - 1 - n + m]){
				flag = 0;
				break;
			}
		}
		ans.push_back(k);
		mp[k]--; if(mp[k] == 0) mp.erase(k);
		mp[k + 1]++;
		auto [k1, v1] = *mp.begin();
		mp[k1]--;
		if(mp[k1] == 0) mp.erase(k1);
	}
	if(!flag){
		cout << -1 << endl;
	}else{
		cout << tt + cs << endl;
		for(auto x: ans) cout << x << " ";
		for(int i = n - m + 1; i <= n; ++ i){
			for(int j = a[i]; j < b[i - n + m]; ++ j) cout << j << " ";
		}
		cout << endl;
	}
}
signed main(){
	ios::sync_with_stdio(0);
	int T;
	cin >> T;
	while(T--) solve();
}

详细

Test #1:

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

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: 10ms
memory: 3780kb

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 Wrong answer, the final sequence does not equal to B (test case 134)