codeforces16B
Burglar and Matches
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than nmatchboxes so that the total amount of matches in them is maximal.
Input
The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer.
Output
Output the only number — answer to the problem.
Examples
7 3
5 10
2 5
3 6
62
3 3
1 3
2 2
3 1
7 sol:显然取个数多的,然后直接按题意贪心模拟即可
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m;
struct Match
{
int Ges,Cnt;
}Box[N];
inline bool cmp_Cnt(Match p,Match q)
{
return p.Cnt>q.Cnt;
}
int main()
{
int i,ans=;
R(n); R(m);
for(i=;i<=m;i++)
{
R(Box[i].Ges); R(Box[i].Cnt);
}
sort(Box+,Box+m+,cmp_Cnt);
for(i=;i<=m&&n;i++)
{
ans+=min(n,Box[i].Ges)*Box[i].Cnt;
n-=min(n,Box[i].Ges);
}
Wl(ans);
return ;
}
/*
Input
7 3
5 10
2 5
3 6
Output
62 Input
3 3
1 3
2 2
3 1
Output
7
*/
codeforces16B的更多相关文章
随机推荐
- 【大数据安全】Apache Kylin 安全配置(Kerberos)
1. 概述 本文首先会简单介绍Kylin的安装配置,然后介绍启用Kerberos的CDH集群中如何部署及使用Kylin. Apache Kylin™是一个开源的分布式分析引擎,提供Hadoop/Spa ...
- 关于PHP打开之后找不到数据库问题的记录
昨天发现了一个奇怪的问题,一直正常使用的某个网站打不开了,这个网站是PHP写的,数据库用的my sql.打开之后就提示密码错误,无法正常打开页面. 由于平时基本上没用过my sql,按照使用sql s ...
- 第二章:shiro身份验证
身份验证,即在应用中谁能证明他就是他本人.一般提供如他们的身份ID一些标识信息来表明他就是他本人,如提供身份证,用户名/密码来证明. 在shiro中,用户需要提供principals (身份)和cre ...
- 原 js实现数据持久化
在写js事件时,常常遇到点击一个事件,然后在若干时间以后需要知道最近一次点击的事件的结点.比如这里: 我点击树节点1,再点击tab2,然后我再来回切换tab,假如最后一次点击tab时在tab2上,这时 ...
- 如何将Eclipse的javaWeb项目改为IDEA的maven项目
1.首先去IDEA开发工具创建一个maven项目,把该项目改为Web项目, a.在pom.xml中,添加packaging标签,值为war b.右键File,选中project structure, ...
- Testlink1.9.17使用方法(第二章 登录&汉化设置)
第二章 登录&汉化设置 QQ交流群:585499566 1,使用超级账户admin/admin登录. 2,登录后,会提示创建一个新的项目,先不要创建,先进入用户管理,设置成中文显示,也就是汉化 ...
- Hive分桶
1.简介 分桶表是对列值取哈希值的方式将不同数据放到不同文件中进行存储.对于hive中每一个表,分区都可以进一步进行分桶.由列的哈希值除以桶的个数来决定数据划分到哪个桶里. 2.适用场景 1.数据抽样 ...
- SQLSTATE[HY000]: General error: 1030 Got error 28 from storage engine
今天上课程化平台考试,输入平台网址突然报这个错误 可以先df -h 发现/tmp文件使用满了 ,清理下不需要的临时文件即可
- 编辑器之神-vim的使用
vim即vi的升级版:在linux中,vi是vim的软链接,我们敲vi和vim出来的都是vim: 纯手打,如有错误,敬请指出. vi的三种模式及简单使用 vi三种模式 命令模式(默认):是文件的入口, ...
- UI自动化之日志
Python自动化测试中,日志输出功能是不能缺少的一部分.让我们来看看如何实现日志的输出吧 一.控制台输出日志 def get_logger(): try: if not os.path.exists ...