社区讨论
咋写
B4450[GESP202512 三级] 小杨的智慧购物参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mjwss3kd
- 此快照首次捕获于
- 2026/01/02 19:35 2 个月前
- 此快照最后确认于
- 2026/01/05 18:00 2 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int n,m,k=0,q=0;
struct cj{
int zl,jg;
}a[10001];
bool cmp(struct cj x,struct cj y){
if(x.zl!=y.zl)return x.zl<y.zl;
else if(x.jg!=y.jg)return x.jg<y.jg;
}
int main()
{
cin>>m>>n;
for(int i=1;i<=n;i++){
cin>>a[i].zl>>a[i].jg;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
if(a[j].zl==i&&q!=a[j].zl){
k+=a[j].jg;
q=a[j].zl;
}
}
}
cout<<k;
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...