题目时间限制为400ms
#include<stdio.h>
int main()
{
int i,m,n,t;
scanf("%d %d",&m,&n);
int d[n],p[n];
for(i = 0 ; i < n ; i++)
scanf("%d %d",&d[i],&p[i]);
int s = (d[1]-d[0])*p[0];
int min = p[0];
for(i = 1 ; i < n ; i++)
{
if(min >= p[i])
{
min = p[i];
t = i;
}
if(i == n-1)
{
s += (m-d[t])*p[t];
m = d[t];
n = t;
i = 1;
}
}
printf("%d",s);
return 0;
}