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
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.

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 <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std; int a[100010];
int p[100010]; int main() {
int n;
cin >> n;
memset(a, 0, sizeof(a));
for (int i = 0; i<n; i++)
cin >> a[i]>> p[i];
int res = 0, min = p[0];
for (int i = 0; i<n; i++) {
if (p[i] < min)
min = p[i];
res += min*a[i];
}
cout << res<< endl;
return 0;
}

A. 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. 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 ...

  3. Codeforce 588A - 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. Codeforces Round #326 (Div. 2)-Duff and Meat

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

  5. Duff and Meat - CF 588A

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

  6. 题解 CF588A 【Duff and Meat】

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

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

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

  8. 数据结构作业——Fresh Meat(优先队列)

    Fresh Meat Description 我们故事的主角是屠夫扒鸡,起初屠夫扒鸡只是一个佣兵,他先去拜了太上老君为师,学了一技能肉钩,凭着一技肉钩驰骋决斗场,达到一段以后到阿尔伯特那里偷学了二技能 ...

  9. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone ...

随机推荐

  1. (一)基于阿里云的MQTT远程控制(Android 连接MQTT服务器,ESP8266连接MQTT服务器实现远程通信控制----简单的连接通信)

    如果不了解MQTT的可以看这篇文章  http://www.cnblogs.com/yangfengwu/p/7764667.html http://www.cnblogs.com/yangfengw ...

  2. JavaScript中的数组对象遍历、读写、排序等操作

    以百度前端技术学院的js任务三为例,复习一下关于js数组的几个点 题目 <!DOCTYPE> <html> <head> <meta charset=&quo ...

  3. Anaconda系统中管理程序包(Package)

    列出所有已安装的程序包 conda list 在已安装的程序包中查找某个特定的程序包 conda search package-name 安装程序包 conda install beautiful-s ...

  4. PHP中引入文件的四种方式及区别

    文件加载语句:include,require,include_once,require_once include,require: require函数通常放在 PHP 程序的最前面,PHP 程序在执行 ...

  5. 小白的Python之路 day5 python模块详解及import本质

    一.定义 模块:用来从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能) 本质就是.py结尾的python文件(文件名:test.py,对应的模块名:test) 包:用来从逻辑上组织模块 ...

  6. [转]Linux网络配置命令ifconfig输出信息解析

    eth0      Link encap:Ethernet  HWaddr 00:1e:4f:e9:c2:84 inet addr:128.224.163.153  Bcast:128.224.163 ...

  7. css3弹性盒模型flex快速入门与上手(align-content与align-items)

    接着上文css3弹性盒模型flex快速入门与上手1继续,上文还剩下两个父容器的属性align-items和align-content. 一.align-content:多行的副轴对齐方式 含义 多行的 ...

  8. 第四章 go语言 数组、切片和映射

    文章由作者马志国在博客园的原创,若转载请于明显处标记出处:http://www.cnblogs.com/mazg/ 数组是由同构的元素组成.结构体是由异构的元素组成.数据和结构体都是有固定内存大小的数 ...

  9. 使用MSHTML解析HTML页面

    最近在写一个爬虫项目,本来打算用C/C++来实现,在网上查找有关资料的时候发现了微软的这个MSHTML库,最后发现在解析动态页面的时候它的表现实在是太差:在项目中需要像浏览器那样,执行JavaScri ...

  10. JPG .vs. PNG

    A summary of comparison between JPEG and PNG JPEG Pros Smaller file size than PNG Widely suppported ...