88分,wa#2,求大佬帮忙
查看原帖
88分,wa#2,求大佬帮忙
1126733
lxc129楼主2024/3/12 10:23
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,sum,ans;
struct node{
    int p,a;
}t[2000001];
bool cmp(node &x,node &y){
    return x.p<y.p;
}
signed main(){
    cin>>m>>n;
    for (int i=1;i<=n;i++) cin>>t[i].p>>t[i].a;
    sort(t+1,t+n+1,cmp);
    for (int i=1;i<=n;i++){
        if (ans+t[i].a<m){
            sum+=t[i].a*t[i].p;
            ans+=t[i].a;
        }
        else{
            cout<<sum+(m-ans)*t[i].p;
            return 0;
        }
    }
}
2024/3/12 10:23
加载中...