此题有一个大坑id范围为1e9
此题题意是按照同类按照价格大小从大到小输出,如果价格相等再按照id从小到大输出。
#include<bits/stdc++.h>
using namespace std;
struct node{
int id;
int score;
int type;
int sell;
bool friend operator < (node a,node b){
if(a.score != b.score) return a.score > b.score;
else if(a.type != b.type) return a.type < b.type;
else if(a.id != b.id) return a.id < b.id;
}
};
map<long long,int> mp1;
set<node> s;
int n,m;
int main()
{
//ios::sync_with_stdio(0);
cin >> m >> n;
for(int i = 0;i < n;i++){
node temp;
cin >> temp.id >> temp.score;
for(int j = 0;j < m;j++){
temp.type = j;
// long long xx = temp.type * 1e9 + temp.id;
// mp1[xx] = temp;
s.insert(temp);
}
}
int num;
cin >> num;
while(num--){
int opt;cin >> opt;
if(opt == 1){
int type;
cin >> type;
node temp;
cin >> temp.id >> temp.score;
temp.type = type;
// long long xx = temp.type * 1e9 + temp.id;
// mp1[xx] = 1;
s.insert(temp);
}
else if(opt == 2){
int type;
cin >> type;
int id;cin >> id;
long long xx = type * 1e9 + id;
mp1[xx] = 1;
}
else if(opt == 3){
int k;cin >> k;
vector<int> g2;
//int sum = 0;
for(int i = 0;i < m;i++){
int t;cin >> t;
g2.push_back(t);
//sum += t;
}
vector<int> ans[55];
int p = k;
// cout << "商品:" << endl;
// for(set<node>::iterator it = s.begin();it != s.end();it++){
//
// node temp = *it;
// cout << temp.type << " " << temp.id << " " << temp.score << endl;
// }
for(set<node>::iterator it = s.begin();it != s.end();it++){
node temp = *it;
int type = temp.type;
long long xx = temp.type * 1e9 + temp.id;
if(mp1.find(xx) != mp1.end()) continue;
if(g2[type] > 0){
p--;
g2[type]--;
ans[type].push_back(temp.id);
//sum--;
}
//if(sum == 0) break;
if(p == 0) break;
}
for(int i = 0;i < m;i++){
int len = ans[i].size();
if(len == 0){
cout << -1 << endl;
}
else{
//sort(ans[i].begin(),ans[i].end());
for(int j = 0;j < len;j++){
cout << ans[i][j];
if(j != len - 1) cout << " ";
}
cout << endl;
}
}
}
}
return 0;
}