水题,简单贪心,学习了一下大神思路,运用桶式排序,代码够简洁
code
/*
ID: yueqiq
PROG: milk
LANG: C++
*/
#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <limits>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string.h>
#include <iostream>
#include <algorithm>
#define Si set<int>
#define LL long long
#define pb push_back
#define PS printf(" ")
#define Vi vector<int>
#define LN printf("\n")
#define lson l,m,rt << 1
#define rson m+1,r,rt<<1|1
#define SD(a) scanf("%d",&a)
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define FF(i,a) for(int i(0);i<(a);i++)
#define FD(i,a) for(int i(a);i>=(1);i--)
#define FOR(i,a,b) for(int i(a);i<=(b);i++)
#define FOD(i,a,b) for(int i(a);i>=(b);i--)
#define readf freopen("milk.in","r",stdin)
#define writef freopen("milk.out","w",stdout)
const int maxn = 1001;
const int INF = 0x3fffffff;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const double pi = acos(-1.0);
using namespace std;
int N,M;
int milk[maxn];
int main(){
readf;
writef;
int need=0;
SD(N);SD(M);
FOR(i,1,M){
int t,u;
SD(t);SD(u);
milk[t]+=u;
}
FF(i,maxn){
if(!milk[i]) continue;
if(!N) break;
if(N>=milk[i]){
N-=milk[i];
need+=milk[i]*i;
}else{
need+=N*i;
N=0;
}
}
PD(need);LN;
return 0;
}