#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
int main()
{
int n;
while(~scanf("%d",&n))
{
int P=1e9;
int ans=0;
for(int i=1;i<=n;i++)
{
int num,pri;
scanf("%d%d",&num,&pri);
gmin(P,pri);
ans+=num*P;
}
printf("%d\n",ans);
}
return 0;
}
/*
【题意】
有n(1e5)天时间,
对于第i天,我们要消耗num[i]单位的食物,
这天如果选择买食物,1单位食物的单价为pri[i],
每天买的食物数量都没有上限,可以囤积到最后。
问你满足这n天的食物需求,最少需要花多少钱。
【类型】
贪心
【分析】
首先,我们发现,如果某天买食物的单价比之后的都低,那我们肯定以这个价买。
这样从前向后有一个阶段性的延展,思考起来和实现起来都有些困难。
于是,我们可以变化一下,做从后向前的思维。
对于每天食用的食物,价格肯定是在它之前的最低价买的。
于是更新一个前缀最低价,这道题就做完了。
*/
【Codeforces Round 326 (Div 2)A】【贪心】Duff and Meat 屯肉前溯花费最低
最新推荐文章于 2018-03-12 19:52:17 发布