假二分,并不是钱越多,买的书就越多。
比如你有14块和12块
13 2 3 4
14块买一本,12块买三本
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set> #include<iomanip> #include <queue> #define endl ' ' #define _for(i,a,b) for(int i=a;i<b;i++) using namespace std; const int N = 1e5+10;//changed typedef long long ll; int n,m; ll a[N]; int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T; cin>>T; while(T--){ cin>>n>>m; int cnt0=0; for(int i=1;i<=n;i++) { cin>>a[i]; if(a[i]==0) cnt0++; } if(n<=m) { cout<<"Richman"<<endl; continue; } if(cnt0>m) { cout<<"Impossible"<<endl; continue; } m -= cnt0; ll ans=0; int i; for (i = 1; i <= n; i++) { if (m == 0) break; if (a[i] == 0) continue; ans += a[i]; m--; } ll mn=0x3f3f3f3f; for(;i<=n;i++) if(a[i]!=0) mn=min(mn,a[i]); cout<<ans+mn-1<<endl; } return 0; }