2 solutions

  • 0
    @ 2022-3-10 9:41:22
    #include<bits/stdc++.h>
    using namespace std;
    int n,m;
    
    struct pp{
    	int a,b;
    }i[25];
    
    bool cmp(pp j,pp k){
    	return j.b>k.b;
    }
    
    int main()
    {
    	cin>>n>>m;
    	for(int c=0;c<m;c++) cin>>i[c].a>>i[c].b;
    	sort(i,i+m,cmp);
    	long long ans=0;
    	for(int c=0;c<m;c++){
    		if(n>i[c].a){
    			ans+=i[c].a*i[c].b;
    			n-=i[c].a;
    		}else{
    			ans+=n*i[c].b;
    			break;
    		}
    	}
    	cout<<ans;
    	return 0;
    }

    Information

    ID
    1896
    Time
    1000ms
    Memory
    64MiB
    Difficulty
    6
    Tags
    # Submissions
    56
    Accepted
    17
    Uploaded By