社区讨论
0分求调,必关
B4452[GESP202512 四级] 优先购买参与者 3已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @mk9pg094
- 此快照首次捕获于
- 2026/01/11 20:23 2 个月前
- 此快照最后确认于
- 2026/01/15 22:55 2 个月前
CPP
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
long long m,n1,a;
string b[1003];
struct xx{
string s;
long long p,v;
}n[1003];
bool cmp1(struct xx x,struct xx y){
return x.p>=y.p;
}
bool cmp2(struct xx x,struct xx y){
if(x.p==y.p)return x.v<=y.v;
}
bool cmp3(struct xx x,struct xx y){
if(x.p==y.p && x.v==y.v)return x.s[1]<=y.s[1];
}
bool cmp4(string x,string y){
return x[1]<=y[1];
}
int main()
{
cin>>m>>n1;
for(int i=1;i<=n1;i++){
cin>>n[i].s>>n[i].p>>n[i].v;
}
sort(n+1,n+1+n1,cmp1);
sort(n+1,n+1+n1,cmp2);
sort(n+1,n+1+n1,cmp3);
for(int i=1;i<=n1;i++){
if(m-n[i].p>=0){
m=m-n[i].p;
b[a]=n[i].s;
a=a+1;
}
}
sort(b+1,b+1+a,cmp4);
for(int i=0;i<=a;i++){
if(b[i]!="")cout<<b[i]<<"\n";
}
return 0;
}
回复
共 6 条回复,欢迎继续交流。
正在加载回复...