A. Duff and Meat
1 second
256 megabytes
standard input
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.
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.
Print the minimum money needed to keep Duff happy for n days, in one line.
3
1 3
2 2
3 1
10
3
1 3
2 1
3 2
8
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的更多相关文章
- 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 ...
- 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 ...
- 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的条件. 思路: 只要判断相邻两天中,今天的总花费 = ...
- Duff and Meat - CF 588A
题目大意:有一个人他有每天需要吃ai千克肉,并且当天肉的价格是pi,问N天后他至少需要花费多少钱买肉. 分析:注意一下,他是可以提前买好肉放着的. 代码如下: #include<iostream ...
- 题解 CF588A 【Duff and Meat】
题意 有一个人,想吃 $n$ 天肉,第 $i$ 天需要吃 $a[i]$ 块肉,第 $i$ 天超市肉价为每块 $b[i]$ 元,买来的肉可以留到后面吃,求这个人在每天都吃到肉的情况下花费的最小值. 题目 ...
- 省钱加油(Fuel Economy)题解
题目 农夫约翰决定去做一个环游国家旅行,为了不让他的奶牛们感到孤单,于是他决定租一辆货车带领他的奶牛们一起去旅行.这辆货车的油箱最多可以承载G 个单位的油,同时为了简化问题,规定每一个单位的油可以行使 ...
- 数据结构作业——Fresh Meat(优先队列)
Fresh Meat Description 我们故事的主角是屠夫扒鸡,起初屠夫扒鸡只是一个佣兵,他先去拜了太上老君为师,学了一技能肉钩,凭着一技肉钩驰骋决斗场,达到一段以后到阿尔伯特那里偷学了二技能 ...
- 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 ...
随机推荐
- kendo ui grid选中行事件,获取combobox选择的值
背景: 以前用 telerik ui做的grid现在又要换成kendo ui,不过说句实话kendo ui真的比telerik好多,可以说超级升级改头换面.当然用的mvc的辅助方法,以前的teleri ...
- ES6 函数的扩展2
8.2 rest参数 ES6引入rest参数(形式为"-变量名"),用于获取函数的多余参数,这样就不需要使用arguments对象了. arguments对象并没有数组的方法,re ...
- hello world 为什么我们看到学习中有这一句话!!!
Hello World ,中文意思:你好,世界.世界上的第一个程序就是Hello World,由Brian Kernighan创作. Hello, world"程序是指在计算机屏幕上输出“H ...
- CentOS7.2 使用Shell安装Oracle12c
一.操作系统说明 1.操作系统 版本 2.磁盘分区用量 二.安装必要的软件包 for pkg in 'binutils' 'compat-libcap1' 'compat-libstdc++-33' ...
- Ansible 系列之 Patterns
Ansible 之 Patterns 1.Ansible中的Patterns决定了我们要管理哪个主机,意思是与哪些主机进行交互. 我们将在Ad-Hoc(Ad-Hoc 是指 临时执行的命令,要结合着模块 ...
- js遍历 子节点 子元素
Js 节点 子元素 属性 方法 // 添加子节点前 删除所有子节点 var usernameEle = document.getElementById("username"); v ...
- Django--admin源码流程
admin.py from django.contrib import admin from . import models """ 通过原生的django admi ...
- Nginx编译配置介绍
源码包 nginx-1.6.2.tar.gz --help 使用帮助 --prefix=PATH Nginx安装路径,如果没有指定,默认为/usr/local/nginx. --sbin-path=P ...
- [Micropython]发光二极管制作炫彩跑马灯
先甩锅 做完后才发现最后一个灯坏了,就坏了一个灯也不好意思去找淘宝店家,大家视频凑合着看把.不过并不影响实验效果.因为这个发光二极管白天不是很明显 晚上炫彩效果就能出来了.本次实验用的是8个灯珠 ...
- wc--Linux
这个命令的功能也很好记,因为它功能很有限: wc -c filename:显示一个文件的字节数 wc -m filename:显示一个文件的字符数 wc -l filename:显示一个文件的行数 w ...