87求助
查看原帖
87求助
826744
ouruiheng0929楼主2023/8/8 15:09

#include <bits/stdc++.h> using namespace std; struct ST{ int p,a; }; ST A[100005]; int n,m,ans=0; bool cmp(ST x,ST y){ if(x.a!=y.a)return x.p<y.p; else return x.p>y.p; } int main(){ cin>>n>>m; for(int i=1;i<=m;i++){ cin>>A[i].p>>A[i].a; } sort(A+1,A+m+1,cmp); int t=n,j=1; while(t>0){ if(t-A[j].a>=0){ ans+=A[j].aA[j].p; } else{ ans+=A[j].pt; } t=t-A[j].a; j++; } cout<<ans; }

2023/8/8 15:09
加载中...