why CE???
查看原帖
why CE???
402269
szkzyc楼主2021/8/14 15:14
#include<iostream>
#include<queue>
#include<algorithm>
#define ll long long
using namespace std;
priority_queue<ll, vector<int>, greater<int> > q;
const int N = 1010;
ll x, y, z, k, tot = 1;
ll a[N], b[N], c[N], ab[N], ans[N]; 
int main(){
    cin >> x >> y >> z >> k;
    for(int i = 1; i <= x; i++) cin >> a[i];
	for(int i = 1; i <= y; i++) cin >> b[i];
	for(int i = 1; i <= z; i++) cin >> c[i];
	sort(a + 1, a + 1 + x);
	sort(b + 1, b + 1 + y);
	sort(c + 1, c + 1 + z);
	for(int i = 1; i <= x; i++){
		for(int j = 1; j <= y; j++){
			if(q.size() < k) q.push(a[i] + b[j]);
			else{
				if(q.top() < a[i] + b[j]) q.pop(), q.push(a[i] + b[j]);
				else break;
			}
		}
	}
	while(!q.empty()){
		ab[tot++] = q.top();
		q.pop();
	}
	for(int i = 1; i <= tot - 1; i++){
		for(int j = 1; j <= z; j++){
			if(q.size() < k) q.push(ab[i] + c[j]);
			else{
				if(q.top() < ab[i] + c[j]) q.pop(), q.push(ab[i] + c[j]);
				else break;
			}
		}
	}
	tot = 1;
	while(!q.empty()){
		ans[tot++] = q.top();
		q.pop();
	}
	for(int i = tot - 1; i >= 1; i--) cout << ans[i] << endl;
	return 0;
}

本地编译正常,AT CE??

2021/8/14 15:14
加载中...