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 ai kilograms of meat.

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.

Examples
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 <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int N=;
const int mod=1e9+;
int a[N],b[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d %d",&a[i],&b[i]);
}
ll s=;
s+=a[]*b[];
int t=b[];
for(int i=;i<n;i++){
if(b[i]<t) t=b[i];
s+=a[i]*t;
}
printf("%lld\n",s);
return ;
}

Codeforce 588A - Duff and Meat (贪心)的更多相关文章

  1. Codeforces Round #326 (Div. 2) A. Duff and Meat 水题

    A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...

  2. A. Duff and Meat

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

  3. Duff and Meat(贪心)

    Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day ...

  4. Duff and Meat - CF 588A

    题目大意:有一个人他有每天需要吃ai千克肉,并且当天肉的价格是pi,问N天后他至少需要花费多少钱买肉. 分析:注意一下,他是可以提前买好肉放着的. 代码如下: #include<iostream ...

  5. Codeforces Round #326 (Div. 2)-Duff and Meat

    题意: Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件. 思路: 只要判断相邻两天中,今天的总花费 = ...

  6. codeforce 810B Summer sell-off (贪心 排序)

    题意: 商店准备用n天售货(每天的货物都是一样的),第i天会卖ki件货物,并且会有li个顾客来买. 如果货物没卖完, 那么每个顾客一定会买一件. 如果货物有剩, 不会保存到第二天. 现在给定一个f, ...

  7. 题解 CF588A 【Duff and Meat】

    题意 有一个人,想吃 $n$ 天肉,第 $i$ 天需要吃 $a[i]$ 块肉,第 $i$ 天超市肉价为每块 $b[i]$ 元,买来的肉可以留到后面吃,求这个人在每天都吃到肉的情况下花费的最小值. 题目 ...

  8. 省钱加油(Fuel Economy)题解

    题目 农夫约翰决定去做一个环游国家旅行,为了不让他的奶牛们感到孤单,于是他决定租一辆货车带领他的奶牛们一起去旅行.这辆货车的油箱最多可以承载G 个单位的油,同时为了简化问题,规定每一个单位的油可以行使 ...

  9. 【LCA】CodeForce #326 Div.2 E:Duff in the Army

    C. Duff in the Army Recently Duff has been a soldier in the army. Malek is her commander. Their coun ...

随机推荐

  1. 浅谈 k8s ingress controller 选型

    大家好,先简单自我介绍下,我叫厉辉,来自腾讯云.业余时间比较喜欢开源,现在是Apache APISIX PPMC.今天我来简单给大家介绍下 K8S Ingress 控制器的选型经验,今天我讲的这些内容 ...

  2. python网络爬虫(二)requests库的基本介绍和使用

    一.requests库的七个重要方法 (1)最常用方法:requests.get(url,params=None,**kwargs)//对应HTTP协议的GET()操作 (请求获得URL位置的资源) ...

  3. scanf函数中*修饰符的作用,如:%*d

    在scanf函数中,*修饰符可以跳过所在项的输入.如下: #include <stdio.h> int main() { ; printf("请输入:"); scanf ...

  4. linux中find文件搜索命令

    find 解释 命令名称:find 命令所在路径:/bin/find 执行权限:所有用户 功能描述:文件搜索 语法 find [搜索范围] [匹配条件] 匹配条件: -name 文件名(区分大小写) ...

  5. Android 有关在ListView RecycleView 中使用EditText Checkbox的坑

    这是一篇文字超多的博客,哈哈哈,废话自行过滤··· 遇到问题 在开发中我们常会在ListView , RecycleView 列表中添加EditText输入框,或者checkbox复选框.   复选框 ...

  6. net start MySQL57 MySQL57 服务正在启动 . MySQL57 服务无法启动。

    造成这种情况的原因有很多,如果直接百度错误信息的话,不一定能很快解决问题,所以,出现这种情况,我们可以使用 mysqld --console 命令来查看报错信息,然后根据报错信息来百度,这样就很快定位 ...

  7. You (oracle) are not allowed to use this program (crontab)

      检查一台ORACLE数据库服务器的crontab作业(用户为oracle,实际环境中可能为oracle.也有可能是其它用户)时,发现出现下面提示信息: $ crontab -l You (orac ...

  8. wifite硬核破解WiFi密码

    如题 楼主在这里分享下如何使用工具破解附近的WiFi 今天使用的工具是 wifite 现在都有WiFi万能钥匙了 暴力破解还有市场吗? 首先他俩的破解思路就不一样 wifi万能钥匙是根据云端数据库内容 ...

  9. Ubuntu安装软件时报 Unable to acquire the dpkg frontend lock解决方案

    解决方案如下: 对于以上内容,请等待过程完成.如果这没有发生,请在终端中运行: sudo killall apt apt-get 如果以上都不起作用,请删除锁定文件.在终端中运行: sudo rm / ...

  10. mysql 不能加载表问题

    记录一次 mysql 5.7 下,出现重启数据库后不能加载特定表的问题处理. 搜索了很多的类似的错误,大多都是说因为外键同名的索引丢失的情况.但在5.7这个版本下,会禁止更新外键关联的索引. 最后经过 ...