【Codeforces Round 326 (Div 2)A】【贪心】Duff and Meat 屯肉前溯花费最低

A. Duff and Meat
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly aikilograms of meat.

【Codeforces Round 326 (Div 2)A】【贪心】Duff and Meat 屯肉前溯花费最低_第1张图片

There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.

Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.

Input

The first line of input contains integer n (1 ≤ n ≤ 105), the number of days.

In the next n lines, i-th line contains two integers ai and pi (1 ≤ ai, pi ≤ 100), the amount of meat Duff needs and the cost of meat in that day.

Output

Print the minimum money needed to keep Duff happy for n days, in one line.

Sample test(s)
input
3
1 3
2 2
3 1
output
10
input
3
1 3
2 1
3 2
output
8
Note

In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.

In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.



#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天的食物需求,最少需要花多少钱。

【类型】
贪心

【分析】
首先,我们发现,如果某天买食物的单价比之后的都低,那我们肯定以这个价买。
这样从前向后有一个阶段性的延展,思考起来和实现起来都有些困难。

于是,我们可以变化一下,做从后向前的思维。
对于每天食用的食物,价格肯定是在它之前的最低价买的。
于是更新一个前缀最低价,这道题就做完了。

*/


你可能感兴趣的:(ACM,ICPC,codeforces,CF326)