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, 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, ..., anand 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<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main() {
int n;
cin>>n;
int a,p;
int sum=0;
int min=0x3f3f3f;
for(int t=0; t<n; t++) {
scanf("%d%d",&a,&p);
if(p<min) {
min=p;
}
sum+=a*min;
}
cout<<sum<<endl;
return 0;
}
Duff and Meat(贪心)的更多相关文章
- 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 ...
- A. Duff and Meat
A. Duff and Meat time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 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 ...
- Codeforces Round #326 (Div. 2)-Duff and Meat
题意: Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件. 思路: 只要判断相邻两天中,今天的总花费 = ...
- 题解 CF588A 【Duff and Meat】
题意 有一个人,想吃 $n$ 天肉,第 $i$ 天需要吃 $a[i]$ 块肉,第 $i$ 天超市肉价为每块 $b[i]$ 元,买来的肉可以留到后面吃,求这个人在每天都吃到肉的情况下花费的最小值. 题目 ...
- Duff and Meat - CF 588A
题目大意:有一个人他有每天需要吃ai千克肉,并且当天肉的价格是pi,问N天后他至少需要花费多少钱买肉. 分析:注意一下,他是可以提前买好肉放着的. 代码如下: #include<iostream ...
- 省钱加油(Fuel Economy)题解
题目 农夫约翰决定去做一个环游国家旅行,为了不让他的奶牛们感到孤单,于是他决定租一辆货车带领他的奶牛们一起去旅行.这辆货车的油箱最多可以承载G 个单位的油,同时为了简化问题,规定每一个单位的油可以行使 ...
- Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题
C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- "贪心"的考试
先来落实比较简单的T3,T4 T3 团结的队伍 team 题目描述 众所周知,长郡信息组是一个团结友爱的优秀团队.为了弘扬团队精神,践行社会主义核心价值观,秉承朴实沉毅的校训,信息组决定外出游玩(. ...
随机推荐
- 数据schemaAvro简介
文章结束给大家来个程序员笑话:[M] 最近在研究Thrift和Avro以及它们的区分,通过各种渠道搜集资料,现整顿出有关Avro的一些资料,方便当前参考. 一.弁言 1. 简介 Avro是Hadoop ...
- docker-建立私有registry
我们知道可以使用hub.docker.com作为我们公共或者私有的registry.但由于服务器在国外的原因,网速会非常的慢.所以我们在利用docker开发构建容器服务时,我们希望能够建立自己的私有r ...
- Java中“分号”引起的陷阱
对于这类问题而言,难度不大,多半是由于我们有误操作引起的.但在查找问题所在的时候我们有可能需要花费一番功夫了. 实例一: package com.yonyou.test; /** * 测试类 * @a ...
- CentOS7下源码安装5.6.23
清理CentOS7下的MariaDB. [root@localhost ~]#rpm -qa | gremp mariadb [root@localhost ~]# rpm -e --node ...
- CSS多列布局Multi-column、伸缩布局Flexbox、网格布局Grid详解
新css属性为我们提供了更加便捷的网页布局方式.来自微软的thomas lewis将带你认识去Grid Alignment,Flexibox Box以及Multi-column Layout这三大领域 ...
- js页面跳转常用的几种方式(转)
js页面跳转常用的几种方式 转载 2010-11-25 作者: 我要评论 js实现页面跳转的几种方式,需要的朋友可以参考下. 第一种: 复制代码代码如下: <script langu ...
- UI线程中非安全操作与安全操作
------------------siwuxie095 工程名:SwingUIThreadSafeTest 包名:com.siwuxie095 ...
- cocos2dx之lua绑定简析
一.总原则:c++对象的生命期不依赖lua gc管理,手动创建的对象要手动销毁 二.引擎层在设计上就是支持脚本概念的(也就是说脚本的使用是“侵入式”的),与lua打交道的代码都封在CCLuaEngin ...
- 分布式系统中Unique ID 的生成方法
http://darktea.github.io/notes/2013/12/08/Unique-ID 本文主要介绍在一个分布式系统中, 怎么样生成全局唯一的 ID 一, 问题描述 在分布式系统存在多 ...
- 截止JDK1.8版本,java并发框架支持锁包括?
读写锁 自旋锁 乐观锁