#include<bits/stdc++.h>
using namespace std;
int n,m,now,cost;
struct milker{
int prize,have;
}a[2000005];
bool cmp(milker a,milker b){
return a.prize<b.prize;
}
int main(){
freopen("milk.in","r",stdin);
freopen("milk.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d",&a[i].prize,&a[i].have);
}
sort(a+1,a+n+1,cmp);
int x=1;
while(n>now){
if(a[x].have>(n-now)){
cost+=(n-now)*a[x].prize;
break;
}
now+=a[x].have;
cost+=a[x].prize*a[x].have;
x++;
}
printf("%d\n",cost);
return 0;
}
在USACO上就是这样的:
Run 1: Execution error: Your program exited with exit status
`127'.