CodeForces - 16B Burglar and Matches【水题】

    科技2022-07-15  142

    题目链接:https://codeforces.com/contest/16/problem/B

    #include <iostream> #include <algorithm> using namespace std; static const int MAXN=20+10; struct Node{ int a,b; bool operator<(const Node &o)const{ return b>o.b; } }match[MAXN]; int n,m; int main() { scanf("%d%d",&n,&m); for(int i=0;i<m;i++) scanf("%d%d",&match[i].a,&match[i].b); sort(match,match+m); int ans=0; for(int i=0;i<m;i++) { if(match[i].a>=n) { ans+=min(match[i].a,n)*match[i].b; break; } ans+=match[i].a*match[i].b; n-=match[i].a; } printf("%d\n",ans); return 0; }
    Processed: 0.010, SQL: 8