ZOJ - 4067

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 .

<h4< dd="">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.

<h4< dd="">Sample Input

4
4 2
1 2 4 8
4 0
100 99 98 97
2 2
10000 10000
5 3
0 0 0 0 1

<h4< dd="">Sample Output

6
96
Richman
Impossible

开始用思维交了一发,WA了。。。
然后错误的发现了自己的“错误”
然后就想到了二分答案
结果。。。崩了。。。
赛后上网搜了一下。。确实是贪心思维题,而且自己的想法没有太大偏差。。。哎
以后还是好好练啊,差的有点多
上代码
 1 /*
 2 加油,别忘记你写这段话时候的心情
 3 如临深渊,如履薄冰
 4 */
 5 #include<bits/stdc++.h>
 6 #include<cstdio>
 7 #include<cstring>
 8 #include<vector>
 9 #include<algorithm>
10 #include<cmath>
11 #include<iostream>
12 #include<queue>
13 #include<set>
14 using namespace std;
15 typedef long long ll;
16 typedef unsigned long long ull;
17 const int maxn = 300000+100;
18 const ll maxn1 = 1e14;
19 
20 vector<int> a; 21 int t,x,n,m; 22 23 int main() 24 { 25 int cnt = 0; 26 scanf("%d",&t); 27 while(t--) 28  { 29  a.clear(); 30 cnt = 0; 31 scanf("%d%d",&n,&m); 32 for(int i = 1; i <= n; i++) 33  { 34 scanf("%d",&x); 35 if(x == 0) cnt++; 36 else a.push_back(x); 37  } 38 if(n == m) 39  { 40 printf("Richman\n"); 41 continue; 42  } 43 if(cnt > m) 44  { 45 printf("Impossible\n"); 46 continue; 47  } 48 m -= cnt; 49 ll sum = 0; 50 ll mx = maxn1; 51 for(int i = 0; i < n - cnt; i++) 52  { 53 if(i < m) sum += a[i]; 54 else 55  { 56 if(mx > a[i]) 57  { 58 mx = a[i]; 59  } 60  } 61  } 62 printf("%lld\n",sum+mx-1); 63  } 64 return 0; 65 }

 

转载于:https://www.cnblogs.com/wxytxdy/p/10672063.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值