题目描述
C++代码
样例
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 4e4 + 10;
int n, m, k;
struct Node {
vector<int> vc;
int ge;
int gi;
double score;
int val;
}node[N],nodecopy[N];
bool cmp(const Node& a, const Node& b)
{
if (a.score == b.score)
{
return a.ge > b.ge;
}
return a.score > b.score;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
vector<int> a(m);
vector<vector<int>> c(m);
for (int i = 0; i < m; i++)
{
cin >> a[i];
}
for (int i = 0; i < n; i++)
{
cin >> node[i].ge >> node[i].gi;
nodecopy[i].ge=node[i].ge;
nodecopy[i].gi=node[i].gi;
node[i].val = i;
node[i].score = double(node[i].ge + node[i].gi) / 2;
nodecopy[i].val = i;
nodecopy[i].score = double(nodecopy[i].ge + nodecopy[i].gi) / 2;
int K = k;
while (K--)
{
int x;
cin >> x;
node[i].vc.push_back(x);
nodecopy[i].vc.push_back(x);
}
}
sort(node, node + n, cmp);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < node[i].vc.size(); j++)
{
int l = node[i].vc[j];
if (a[l] > 0)
{
c[l].push_back(node[i].val);
a[l] -= 1;
break;
}
else{
int t=c[l].back();
if(node[i].score==nodecopy[t].score&&node[i].ge==nodecopy[t].ge)
{
c[l].push_back(node[i].val);
break;
}
}
}
}
for (int i = 0; i < m; i++)
{
if (c[i].size() > 0)
{
sort(c[i].begin(), c[i].end());
for (int j = 0; j < c[i].size(); j++)
{
if (j != (c[i].size() - 1))
{
cout << c[i][j] << " ";
}
else {
cout << c[i][j];
}
}
}
cout << endl;
}
return 0;
}