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. 调用CMD命令的一个.NET工具类(MyWindowsCmd)

    功能大概描述一下如果直接StandardOutput.ReadToEnd()这种方法,有很多限制 这类方式必须把命令全部执行一次写入并标记为exit,而且返回内容的获取会一直等待,如果在主线程里使用会 ...

  2. OpenStack运维(一):OpenStack项目和用户

    1.添加项目 keystone tenant-create --name=demo [--description tenant-description --enable false] demo:项目名 ...

  3. 第四节 mount /who / mkdir /rmdir /rm /cp /mv /touch /cat /tac/head /tail /more /less / chmod /chown /umask /chattr /lsattr /history /echo

    ***Linux下的文件类型如下: 9 8 7 6 5 4 3 2 1 0- r w x r - x r - x 第9位表示文件类型,可以为p.d.l.s.c.b和-:p表示命名管道文件 -pipe ...

  4. flask_restful 学习笔记

    from flask import Flask,make_response,jsonify,request,url_for,g from flask_restful import reqparse, ...

  5. Ajax异步提交登录(2)--登录使用

    http://cjp1989.iteye.com/blog/1740964 1.Ajax的原理: Ajax的原理就是:通过javascript的方式,将前台数据通过xmlhttp对象传递到后台,后台在 ...

  6. popupwindow那些坑

    1. new PopupWindow(vw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 如果 ...

  7. SQL SERVER 日期转换大全

    博客转自:http://blog.csdn.net/baiduandxunlei/article/details/9180075 CONVERT(data_type,expression[,style ...

  8. QCanvasItem介绍-QT3

    QCanvasItem类提供一个在QCanvas上的抽象图形对象. 各种QCanvasItem子类提供立即可用的行为.这个类是一个纯粹的抽象超类,它提供了在所有具体的canvas项目类中共享的行为.Q ...

  9. 关于xml文档使用出现的错误及其解决方法

    在学习xml的时候在运行下面程序时候出现了错误,很是烦恼,翻遍了许多博客都没有找到方法,终于在一个不起眼的地方找到了解决方法,很高兴记录下来 运行的程序如下: import xml.etree.Ele ...

  10. 关于S/4HANA里Sales Office 和Sales Organization那些事儿

    今天这篇文章来自我的成都同事Zhang Sean(张正永). Sean也是一位在SAP行业摸爬滚打多年的老兵了,2009年从大学硕士毕业之后就进入了SAP Labs从事开发工作,目前是SAP 成都S/ ...