2 solutions

  • 0
    @ 2022-3-10 23:36:39

    斗胆把代码贴在这里,写的不好请多担待

    #include<iostream>
    #include<algorithm>
    using namespace std;
    long long int n,m,ans;
    struct A{
    	int a,b;
    }p[27];
    
    bool cmp(A x,A y){
    	return x.b>y.b;
    }
    int main(){
    	cin>>m>>n;
    	for(int i=0;i<n;i++){
    		cin>>p[i].a>>p[i].b;
    	}
    	sort(p,p+n,cmp);
    	int t=0;
    	while(m){
    		if(p[t].a<m){
    			ans+=p[t].b*p[t].a;
    			m-=p[t].a;
    		}
    		else {
    			ans+=m*p[t].b;
    			m=0;
    			}
    		t++;
    		if(t==n)break;
    	}
    	cout<<ans;
    	return 0;
    }
    
    • @ 2022-3-12 18:54:09

      ? 你又发啥子颠喔

  • 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;
    }
    • 1

    Information

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