博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Books
阅读量:5233 次
发布时间:2019-06-14

本文共 2439 字,大约阅读时间需要 8 分钟。

Books

DreamGrid went to the bookshop yesterday. There are  books in the bookshop in total. Because DreamGrid is very rich, he bought the books according to the strategy below:

  • Check the  books from the 1st one to the -th one in order.
  • For each book being checked now, if DreamGrid has enough money (not less than the book price), he'll buy the book and his money will be reduced by the price of the book.
  • In case that his money is less than the price of the book being checked now, he will skip that book.

BaoBao is curious about how rich DreamGrid is. You are asked to tell him the maximum possible amount of money DreamGrid took before buying the books, which is a non-negative integer. All he knows are the prices of the  books and the number of books DreamGrid bought in total, indicated by .

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers  and  (), indicating the number of books in the bookshop and the number of books DreamGrid bought in total.

The second line contains  non-negative integers  (), where  indicates the price of the -th book checked by DreamGrid.

It's guaranteed that the sum of  in all test cases will not exceed .

Output

For each test case output one line.

If it's impossible to buy  books for any initial number of money, output "Impossible" (without quotes).

If DreamGrid may take an infinite amount of money, output "Richman" (without quotes).

In other cases, output a non-negative integer, indicating the maximum number of money he may take.

Sample Input

44 21 2 4 84 0100 99 98 972 210000 100005 30 0 0 0 1

Sample Output

696RichmanImpossible

 模拟题,先把0的个数判断出来,后面贪心即可

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #define maxn 20000510 #define INF 0x3f3f3f3f3f3f3f3f11 using namespace std;12 13 long long a[maxn];14 15 int main(){16 int t;17 cin>>t;18 int n,m;19 while(t--){20 long long ans=0;21 cin>>n>>m;22 long long Min=INF;23 int zero=0;24 for(int i=1;i<=n;i++){25 cin>>a[i];26 if(!a[i]) zero++;27 if(Min>a[i]) Min=a[i];28 }29 if(n==m) cout<<"Richman"<
a[i]&&a[i]){49 tmp=a[i];50 }51 }52 ans+=tmp-1;53 if(flag){54 cout<<"Impossible"<
View Code

 

转载于:https://www.cnblogs.com/Fighting-sh/p/9908769.html

你可能感兴趣的文章
java之http协议
查看>>
如何将Excel导入到DataGridView中
查看>>
高级sed编程
查看>>
Android自定义Dialog效果
查看>>
第一章 安装webpack
查看>>
跳一跳辅助使用教程
查看>>
还不错的html5引擎
查看>>
腾讯云服务器遭到勒索病毒经历
查看>>
tomcat安装
查看>>
Django知识点
查看>>
使用JExcelAPI组件操作Excel文件
查看>>
php模块memcache和memcached区别分析
查看>>
字符串匹配dp+bitset,滚动数组优化——hdu5745(经典)
查看>>
1月28日 表单验证和正则表达式
查看>>
正则表达式
查看>>
基于openfire的ios聊天demo
查看>>
3D游戏中的画质与效率适配
查看>>
Linux 命令
查看>>
字符串中字符调换
查看>>
用C#编写猜数、九九乘法表‘、迷宫
查看>>