问题标题: 酷町堂:2605

0
0
已解决
曾心
曾心
高级守护
高级守护

题目链接: 酷町堂:2605

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <stdio.h>
#include <string>
using namespace std;
long long n,m,cnt,summ; 
struct p{
    long long dj,l;
}a[5005]; 
bool cmp(p x,p y){
    return x.dj<y.dj;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a[i].dj>>a[i].l;
    }
    sort(a+1,a+m+1,cmp);
    for(int i=1;i<=n;i++){
        if(cnt>=n){
            break;
        }
        cnt+=a[i].l;
        summ+=a[i].dj;
    }
    cout<<summ;
    return 0;
}


0
我要回答