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. 关于博客中引用多媒体出现的bug说明

    插件说明 Aplayer.Dplayer @DIYgod 大佬在gihub的开源项目,对此,表示非常之感谢!! Aplayer 支持放在页首 支持放在页尾 但是不支持直接放在文章中引用 解决方法: 1 ...

  2. xml文件解析(使用解析器)

    一.Xml解析,解析xml并封装到list中的javabean中 OM是用与平台和语言无关的方式表示XML文档的官方W3C标准.DOM是以层次结构组织的节点或信息片断的集合.这个层次结构允许开发人员在 ...

  3. java中可变长参数

    ** * Created by Lenovo on 2017/12/10. * java中可变长参数 */ public class reflect04 { //m1有一个int类型的可比变长参数 / ...

  4. Search an Element in an array

    Given an integer array and an element x, find if element is present in array or not. If element is p ...

  5. js变量提升与函数提升

    在es6之前,js语言并没有块级作用域,即{}形成的作用域,只有全局作用域和函数作用域,所谓的提升,即是将该变量的声明或者函数的声明提升,举个例子 console.log(global); //und ...

  6. CSS3 使用选择器在页面插入内容

    使用选择器来插入文字 h2:before{ content:'COLUMN'; color:white: background-color:orange: padding:1px 5px; } 注意点 ...

  7. & 与 kill -3

    mysqld_safe --defaults-file=/app/3307/my.cnf 2>&1 1>/dev/null & 将mysqld服务进程放入后台后, 因为忘记 ...

  8. Python3 实现数据读写分离设计

    前言 首先读写分离可以保证数据库的稳定,简单的说就是当网站访问量大时,读写都在一个库,很有可能会出现脏数据的情况,如果采取阻塞似操作,那么用户体验就会变得更差. 而且目前大多数网站的读写是失衡的,以淘 ...

  9. a标签实现一键拨号、发短信、发邮件、发起QQ会话

    a标签href的妙用:   <a href="tel:400-888-6633">拨打电话<a> <a href="sms:19956321 ...

  10. K:java中枚举的常见用法

    用法一:常量   在JDK1.5 之前,我们定义常量都是: public static fianl.....现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多的方法. ...