Codeforces Round #109 (Div. 2)——B
来源:互联网 发布:网上买书的软件 编辑:程序博客网 时间:2024/06/01 10:30
Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number ai, and the bottom contains number bi, then when the player is playing the card, he gets ai points and also gets the opportunity to play additional bi cards. After the playing the card is discarded.
More formally: let's say that there is a counter of the cards that can be played. At the beginning of the round the counter equals one. When a card is played, the counter decreases by one for the played card and increases by the number bi, which is written at the bottom of the card. Then the played card is discarded. If after that the counter is not equal to zero, the player gets the opportunity to play another card from the remaining cards. The round ends when the counter reaches zero or the player runs out of cards.
Of course, Ilya wants to get as many points as possible. Can you determine the maximum number of points he can score provided that you know his cards?
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of cards Ilya has.
Each of the next n lines contains two non-negative space-separated integers — ai and bi (0 ≤ ai, bi ≤ 104) — the numbers, written at the top and the bottom of the i-th card correspondingly.
Print the single number — the maximum number of points you can score in one round by the described rules.
21 02 0
2
31 02 00 2
3
In the first sample none of two cards brings extra moves, so you should play the one that will bring more points.
In the second sample you should first play the third card that doesn't bring any points but lets you play both remaining cards.
#include <iostream>#include <cstdio>#include <algorithm>#define maxn 1200using namespace std;struct Node{ int top,bot;} card[maxn];//容易得知:若要尽可能多的拿分,先要保证有足够的点数,所以对bi降序排列,再对ai降序排列bool cmp(Node x,Node y){ if(x.bot!=y.bot) return x.bot>y.bot; else return x.top>y.top;}int a[maxn];int main(){ int n,i; scanf("%d",&n); for(i=0; i<n; i++) scanf("%d%d",&card[i].top,&card[i].bot); sort(card,card+n,cmp); int sum=0,cnt=0; sum+=card[0].top; cnt+=card[0].bot; for(i=1; i<n; i++) { if(cnt==0) break; sum+=card[i].top; cnt+=card[i].bot-1; } printf("%d\n",sum); return 0;}
- Codeforces Round #109 (Div. 2)——B
- Codeforces Round #154 (Div. 2)——B
- Codeforces Round #156 (Div. 2)——B
- Codeforces Round #151 (Div. 2)——B
- Codeforces Round #152 (Div. 2)——B
- Codeforces Round #149 (Div. 2)——B
- Codeforces Round #146 (Div. 2)——B
- Codeforces Round #144 (Div. 2)——B
- Codeforces Round #142 (Div. 2)——B
- Codeforces Round #157 (Div. 2)——B
- Codeforces Round #134 (Div. 2)——B
- Codeforces Round #141 (Div. 2)——B
- Codeforces Round #140 (Div. 2)——B
- Codeforces Round #137 (Div. 2)——B
- Codeforces Round #136 (Div. 2)——B
- Codeforces Round #135 (Div. 2)——B
- Codeforces Round #124 (Div. 2)——B
- Codeforces Round #123 (Div. 2)——B
- C&lua生成新配置
- 用css控制cellspacing、cellpadding
- 【iOS知识学习】_tableview滑动时图片加载缓慢解决办法
- 随机数,和,平均值
- 从网络下载内核和挂载文件系统
- Codeforces Round #109 (Div. 2)——B
- Windows Phone 7入门经典:使用Silverlight和XNA开发Windows Phone应用
- 推荐16个下载超酷脚本的免费热门网站
- VC编译器使用技巧、警告和错误解决办法等杂项
- java" selection does not contain a main type"的问题处理方法
- s3c6410 ddr初始化
- C++内联函数(Inline)介绍
- 使用Easy_install 安装python站点包
- Python : 计算大文件MD5值